繁体   English   中英

Google Places API不返回几何

[英]Google places api not returning geometry

我正在使用“ google place autocomplete API”来使用类似的javascript获取有关不同城市的数据:

var service = new google.maps.places.Autocomplete(document.getElementById('search-btn'));
service.addListener('place_changed', function () { 
    var place = service.getPlace();
    console.log(place.geometry.location);
});

问题:对象不具有(lat,lng)但它具有此消息

TypeError:“ caller”和“ arguments”是受限制的函数属性,在此上下文中无法访问。

在Function.remoteFunction(:3:14)

在Object.InjectedScript.callFunctionOn(:750:66)

我似乎也有同样的问题。 地图工作正常,昨天返回了几何图形,今天它只是空白,没有经度/纬度,并且存在相同的错误。

似乎他们更新了API,但出现了问题

编辑:

对我来说,它可以通过获取标记坐标来解决,而不是尝试对其进行地址解析,然后再获取地址的后代。

我有这样的代码(工作12.10.15):

function geocodePosition(pos) 
            {
               geocoder = new google.maps.Geocoder();
               geocoder.geocode
               ({
                    latLng: pos
                }, 
                    function(results, status) 
                    {
                        if (status == google.maps.GeocoderStatus.OK) 
                        {
                            $("#address").val(results[0].formatted_address);
                            $("#id_location_0").val(results[0].geometry.location.J);
                            $("#id_location_1").val(results[0].geometry.location.M);
                        } 

                    }
                );
            }

此人停止工作,但能够通过从标记中获取坐标来进行修复。 Pos变量在我的情况下是marker.getPosition()。

                        if (status == google.maps.GeocoderStatus.OK) 
                        {
                            $("#address").val(results[0].formatted_address);
                            $("#id_location_0").val(marker.position.lat());
                            $("#id_location_1").val(marker.position.lng());
                        } 

似乎已报告https://code.google.com/p/gmaps-api-issues/issues/detail?id=8734

您可以尝试:

var service = new google.maps.places.Autocomplete(document.getElementById('search-btn'));
service.addListener('place_changed', function () { 
    var place = service.getPlace();
    console.log(place.geometry.location.lat(), place.geometry.location.lng());
});

我有同样的问题。 我的Lat和Lng似乎是函数,但也有错误。 为了获得实际值,您必须实际调用lat和long as函数,并将其分配给回调中的变量。

  geocoder = new google.maps.Geocoder();
  geocoder.geocode({'address' : addressString}, function(results, status){
    if(status == google.maps.GeocoderStatus.OK){

         ///~~~~~~~~~The part you care about ~~~~~~~~~~///
          var lat = results[0].geometry.location.lat();
          var lng = results[0].geometry.location.lng();

      console.log(lat); // --> 37.7603726
      console.log(lng); // --> -122.47157
    }
  });

临时解决方案:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM