Monday, October 27, 2008

Reverse geocoding on Big map

Big map mashup supports a new Google Maps API feature - reverse geocoding. Try to click on the map - you will see the address. The following code does the job:


geocoder=new GClientGeocoder();
GEvent.addListener(map, "click", clickFunction);

...

function clickFunction(overlay, latlng) {
if (latlng)
{
geocoder.getLocations(latlng, function(addresses) {
if(addresses.Status.code != 200) {
alert("Google reverse geocoder failed to find an address for " + latlng.toUrlValue());
}
else
{ address = addresses.Placemark[0];
var myHtml = address.address;
map.openInfoWindow(latlng, myHtml); }
});
}
}

No comments: