I am using the following function to get latitude and longitude values:
pre//return lat & lng values of a postcode
var geocoder;
geocoder = new google.maps.Geocoder();
function codeAddress(address) {
var result = '';
geocoder.geocode( { 'address': address, 'region': 'uk' }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
result['lat'] = results[0].geometry.location.lat();
console.log("results[0] = ",results[0]);
result['lng'] = results[0].geometry.location.lng();
} else {
result = "Unable to find address: " + status;
}
});
return result;
}/pre
It always returns an empty string. i am passing it a uk postcode
I think maybe part of my problem is that it is aynchronous which possibly means that 'result' is returned before it has allocated a value.