Google地图地理编码:未定义的纬度

时间:2011-07-07 09:24:39

标签: google-maps geocoding

点击跟随脚本的页面显示:

  • lat:undefined
  • lon:51.5001524

为什么lat未定义,lon不是? 可以找到一个工作示例here

拉起你的网络控制台,亲眼看看!

              

$(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>

虽然我们在这里 - Ia和Ja的历史意义是什么?我认为它与笛卡尔单位向量i和j有关(主要用于工程)但我不确定。

我在网上找到了其他使用.lat .Ia.lng .Ja

的例子

但是,这些会在控制台中返回:

function () {
    return this[a];
}

只需要朝正确的方向迈进。 谢谢。

3 个答案:

答案 0 :(得分:5)

我会使用lat()lng()

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

答案 1 :(得分:1)

这是地理编码器的设计行为:google在

中移动标识符
geometry.location.Ia;
geometry.location.Ja;

每周一次,即从上到下

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

等等,因此无法通过id引用地理编码器结果对象。

答案 2 :(得分:1)

Google可能会使用javascript minifier(例如http://jscompress.com/)来重命名所有变量 - 因此它们可能会在每次构建时发生变化。