我试图使用以下代码通过地址获取纬度和经度:
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);
}
问题是 results[0].geometry.location.latitude 和 longitude 未定义。
我在控制台中看到的结果如下:
location: O
$a: 51.5414691
ab: -0.11492010000006303
为什么显示 $a 和 ab 而不是纬度和经度
使用以下函数而不是直接访问属性:
results[0].geometry.location.lat()
and
results[0].geometry.location.lng()
Google 代码经过混淆处理,内部使用的短变量名称可能会随时发生变化。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)