Google Maps API - geocode()不会返回经纬度 [英] Google Maps API - geocode() doesn't return lat and long

查看:143
本文介绍了Google Maps API - geocode()不会返回经纬度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 函数初始化(){
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] .geomety.location.latitude和longitude



我在控制台的结果中看到的是下一个:

  location:O 

$ a:51.5414691

ab:-0.11492010000006303

为什么它显示$ a和ab而不是经度和纬度?

解决方案

使用以下函数,而不是直接访问属性:

  results [0] .geometry.location.lat()

 结果[0] .geometry.location.lng()

Google代码被混淆并且在内部使用short变量名称可能会从一天变为另一天。


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:

results[0].geometry.location.lat()

and

results[0].geometry.location.lng()

The Google code is obfuscated and internally uses short variable names that can change from one day to another.

这篇关于Google Maps API - geocode()不会返回经纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆