最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Google geocoder failing due to over_query_limit - Stack Overflow

programmeradmin2浏览0评论

I'm filling four form fields using reverse geocoding. The form fills correctly but then I receive an error stating OVER_QUERY_LIMIT. On checking the JS console of chrome I see that five identical calls have been made before I received the error message. I'm unsure why my code is making several requests. Could someone please point out what I should change in my loops in the codeLatLng function. That's most likely where the problem is.

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." );
  }
});

Many Thanks in advance.

I'm filling four form fields using reverse geocoding. The form fills correctly but then I receive an error stating OVER_QUERY_LIMIT. On checking the JS console of chrome I see that five identical calls have been made before I received the error message. I'm unsure why my code is making several requests. Could someone please point out what I should change in my loops in the codeLatLng function. That's most likely where the problem is.

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." );
  }
});

Many Thanks in advance.

Share Improve this question edited May 13, 2012 at 21:51 M4bhat asked May 13, 2012 at 20:09 M4bhatM4bhat 431 gold badge1 silver badge5 bronze badges 2
  • This can't be all your code, because at the moment getCity() is not called, which means that geocoder is never defined and geocoder.geocode() will fail. – Andrew Leach Commented May 13, 2012 at 23:03
  • You might have to provide more code, a link to the page, or set up a jsFiddle page. I don't see a loop within the codeLatLng function. I can't see how the geocoder is getting called in a loop. – Sean Mickey Commented May 13, 2012 at 23:05
Add a ment  | 

1 Answer 1

Reset to default 3

Use of the Google Maps API Web Services is subject to specific limits on the amount of requests per day allowed.

OVER_QUERY_LIMIT is caused by this restriction.

Here you can find more information:

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

You can try to wait over 2 seconds when google responds with this error, for example, with a setTimeout.

It could be that results[0].address_ponents[i] will be a reference to a function call.

发布评论

评论列表(0)

  1. 暂无评论