我试图通过地址用下面的代码来获得纬度和经度:谷歌地图API - 地理编码()不返回lat和长
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);
}
的问题是,结果[0]。几何位置,海拔和经度都未知。
我在控制台结果中看到什么是下一个:
location: O
$a: 51.5414691
ab: -0.11492010000006303
为什么它显示$ a和的直接访问AB代替纬度和经度
非常好,thx! – Alon
而在你的例子中,你不必创建一个新的'google.maps.LatLng'; 'results [0] .geometry.location'_is_a google.maps.LatLng'。 –
@Sean Mickey,也许你可以帮助解决另一个问题,我似乎无法将该数据保存到脚本中的变量中。我如何保存并使用它? – Alon