I have the following code:
var address;
getAddress(0,0);
function getAddress(latlng)
{
if (latlng != null)
{
geocoder.getLocations(latlng,
function(addresses)
{
if(addresses.Status.code == 200)
{
address = addresses.Placemark[0].address.toString();
alert(address); // Outputs something :)
}
});
}
return address; //returns nothing :(
}
I am very new to javascript and don't know why address always returns undefined but the alert does output something.
geocoder is an instance of google maps apis http://code.google.com/apis/maps/documentation/reference.html#GClientGeocoder