I have a working Map function that uses a little bit of jQuery to fetch JSON data. I have been trying for hours to update the function for use with Maps 3.X API to no avail. I'm not very well versed with Javascript and I made this function sometime last year.
Basically the function requires some parameters to query a url and get JSON data which has LatLong information that it passes on to the Map object.
The internal_id parameter is an HTML identifier for the where the Map & Street View should be loaded into.
The function handles some errors and allows the user to click on a nearby road if there is no street view information in the initial LatLong data given.
If there is one, it updates the info window in the map to reflect current street address (this part isn't working all that well!)
function get_map(street, internal_id, url, type)
{
jQuery.getJSON(url,
{
street: street,
type: type
}, function(data)
{
var map;
var street_view_pano;
var street_view;
var pano_id;
var latlng = new GLatLng(data.lat, data.long);
street_view = new GStreetviewClient();
map = new GMap2(document.getElementById('m' + internal_id));
map.setCenter(latlng, 14);
map.setUIToDefault();
map.addOverlay(new GMarker(latlng));
GEvent.addListener(map, "click", function(overlay, latlng)
{
street_view.getNearestPanorama(latlng, showPanoData);
});
street_view_pano = new
GStreetviewPanorama(document.getElementById('p' + internal_id));
street_view_pano.setLocationAndPOV(latlng);
GEvent.addListener(street_view_pano, "error", handleNoFlash);
street_view.getNearestPanorama(latlng, showPanoData);
function showPanoData(panoData)
{
if (panoData.code != 200)
{
jQuery('#p' + internal_id).html('<div id="no_map">We couldn\'t find a Street View for this property. Try zooming in the <span class="enlarge">Map</span> and clicking on a nearby road.</div>');
return;
}
else
{
var street_div_id = '#p' + internal_id;
jQuery(street_div_id).text('');
}
pano_id = panoData.links[0].panoId;
var info_text = '<table id="description">' + street + '</table>';
map.openInfoWindowHtml(panoData.location.latlng,
info_text);
street_view_pano.setLocationAndPOV(panoData.location.latlng);
}
function next()
{
street_view.getPanoramaById(pano_id, showPanoData);
}
function handleNoFlash(errorCode)
{
if (errorCode == 603)
{
jQuery('#p' + internal_id).html('<divid="no_map">There is a problem with Flash in your browser. Street-Viewwill not be shown</div>');
return;
}
}
});
}