【问题标题】:Google geocoder failing due to over_query_limit由于 over_query_limit 导致 Google 地理编码器失败
【发布时间】:2012-05-13 20:09:02
【问题描述】:

我正在使用反向地理编码填写四个表单域。表单填写正确,但随后我收到一条错误消息,指出 OVER_QUERY_LIMIT。在检查 chrome 的 JS 控制台时,我看到在收到错误消息之前已经进行了五个相同的调用。我不确定为什么我的代码会发出多个请求。有人可以指出我应该在 codeLatLng 函数的循环中更改什么。这很可能是问题所在。

var geocoder;

function getCity() {
    geocoder = new google.maps.Geocoder();  
  }


  if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(successFunction, errorFunction);
} 
//Get the latitude and the longitude;
function successFunction(position) {
    var lat = position.coords.latitude;
    var lng = position.coords.longitude;
    //alert("Success funciton" + lat + " " + lng);
    codeLatLng(lat, lng)    
}

function errorFunction(){
    AppMobi.notification.alert("For the best user experience, please ensure your device GPS and geolocation settings are enabled.","Geolocation disabled","OK");
}

    function codeLatLng(lat, lng) {
    //alert("codeLatLng fn started");
    var latlng = new google.maps.LatLng(lat, lng);
    geocoder.geocode({'latLng': latlng}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
      console.log(results)
        if (results[1]) {
         //formatted address
     //alert(results[0].formatted_address) //Complete address
    $("#address1").val(results[0].formatted_address);
    } else {
      alert("No results found. Please enter the data manually.");
    }
  } else {
    alert("Geocoder failed due to: " + status +".  Please enter the data manually." );
  }
});

非常感谢。

【问题讨论】:

  • 这不可能是你的全部代码,因为此时getCity() 没有被调用,这意味着geocoder 永远不会被定义并且geocoder.geocode() 将会失败。
  • 您可能需要提供更多代码、页面链接或设置 jsFiddle 页面。我在codeLatLng 函数中看不到循环。我看不到地理编码器是如何被循环调用的。

标签: javascript google-maps-api-3


【解决方案1】:

Google Maps API 网络服务的使用受到每天允许的请求数量的特定限制。

OVER_QUERY_LIMIT 是由这个限制引起的。

在这里您可以找到更多信息:

https://developers.google.com/maps/documentation/business/articles/usage_limits

当 google 响应此错误时,您可以尝试等待超过 2 秒,例如,使用 setTimeout。

results[0].address_components[i] 可能是对函数调用的引用。

【讨论】:

  • 您好,感谢您的回复。我理解谷歌的限制。我无法确定我的代码中是什么导致了多个请求(我只想发出一个请求!)。阅读您的评论后,我尝试完全注释掉 results[0].address_components[i] 。相反,只需在表单字段中输入一大段文本作为地址(例如:123 Fake Ave., SomeCity, SomeState, SomeCountry)。但是,我仍然看到同样的错误。 :(.. 还有其他建议吗?
  • 我在您的新代码中看不到任何内容:(。我建议将所有内容简化为对 geocoder.geocode 的简单调用并将其与所有其他代码隔离开来。可能是您覆盖了一些地理编码函数(变量)?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-20
相关资源
最近更新 更多