开发者

Google Maps geocode: undefined latitude

开发者 https://www.devze.com 2023-03-18 09:38 出处:网络
Hitting a page with the follow script displays: lat: undefined lon: 51.5001524 Why is it that while lat is undefined, lon is not?

Hitting a page with the follow script displays:

  • lat: undefined
  • lon: 51.5001524

Why is it that while lat is undefined, lon is not? A working example can be found here.

Pull up your web console and see for yourself!

$(document).ready(function(){

var geocoder;
function codeAddress() 
{
    geocoder = new google.maps.Geocoder();
    var address = 'London, England';
    geocoder.geocode({'address': address}, function(results, status) 
    {   
      if (status == google.maps.GeocoderStatus.OK) 
      {
        lat = results[0].geometry.location.Ia;
        lon = results[0].geometry.location.Ja;

        console.log("lat: " + lat);
        console.log("lon: " + lon);
      }
    });
}
    codeAddress();
});
</script>
</head>
<body>
</body>
</html>

While we'开发者_C百科re at it - what is the historical significance of Ia and Ja? I presume it relates to the Cartesian unit vectors i and j (predominately used in Engineering) though I'm not sure.

I found other examples online who use .lat for .Ia and .lng for .Ja

These, however, are returning in the console:

function () {
    return this[a];
}

Just need a kick in the right direction. Thank you.


I would use lat() and lng():

var lat = results[0].geometry.location.lat();
var lng = results[0].geometry.location.lng();


This is a designed behaviour of the geocoder: google shifts the identifiers in

geometry.location.Ia;
geometry.location.Ja;

on a weekly basis, i.e. from above to

geometry.location.Ja;
geometry.location.Ka;

and so on, so it is not possible to refer by id to the geocoder result object.


Chances are Google are using a javascript minifier (e.g. http://jscompress.com/) which renames all variables - hence they're subject to change on every build.

0

精彩评论

暂无评论...
验证码 换一张
取 消