Hi,
I'm using the Google maps geocoder to get latitudinal and longitudinal coordinates from a passed in address.
The callback function getGeocode() is returning the coordinates and saved into the local variable 'point'.
The issue I'm having is the point value is not seen outside of getGeocode function even
though the local variable 'point' is global to the function.
I was hoping to return the local variable point from the getAddrs() function. How can I get the variable 'point' passed back from
the function getAddrs().
From Firefox console.log, both 'apoint' and 'cpoint' is undefined. 'bpoint' has the coordinates (-32.829,116.32222).
I'm using it like so:
var address = "1010 Blossom Lane,Spring Valley,CA"
var apoint = getAddrs(address);
console.log('apoint: %s', point);
function getAddrs(address)
{
var point;
// Create new geocoding object
geocoder = new GClientGeocoder();
if (address != '')
{
// Retrieve location information, pass it to getGeocode()
geocoder.getLocations(address,getGeocode);
}
//Get Latitude and Longitude
function getGeocode(response)
{
// Retrieve the object
place = response.Placemark[0];
// Retrieve the latitude and longitude
point = new GLatLng(place.Point.coordinates[1],
place.Point.coordinates[0]);
console.log('bpoint: %s', point);
}
console.log('cpoint: %s', point);
return point;
}