I’m trying to get a latitude and longitude by address with the following code:
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
geocoder = new google.maps.Geocoder();
var address = "HaYarkon 100 TelAviv Israel";
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK)
{
TelAviv = new google.maps.LatLng(results[0].geometry.location.latitude,results[0].geometry.location.longitude);
}
});
var myOptions = {
zoom:7,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: TelAviv
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
directionsDisplay.setMap(map);
}
The problem is that results[0].geomety.location.latitude and longitude are undefinde.
What I see in the results in the console are the next:
location: O
$a: 51.5414691
ab: -0.11492010000006303
Why does it show $a and ab instead of latitude and longitude
Use the following functions instead of directly accessing the properties:
and
The Google code is obfuscated and internally uses short variable names that can change from one day to another.