Вы превысили свою ежедневную квоту запроса для этого API. даже используя ключ api [дубликат]

22
задан Benjamin 10 April 2014 в 17:08
поделиться

3 ответа


Этот подход не является правильным сигналом перегрузки Google Server. Для получения дополнительной информации см. https://gis.stackexchange.com/questions/15052/how-to-avoid-google-map-geocode-limit#answer-15365


Кстати, если вы все равно хотите продолжить, здесь вы можете найти код, который позволяет загружать несколько маркеров ajax, полученных на картах google, избегая ошибки OVER_QUERY_LIMIT.

Я протестировал на своем onw сервере и он работает!:

var lost_addresses = [];
    geocode_count  = 0;
    resNumber = 0;
    map = new GMaps({
       div: '#gmap_marker',
       lat: 43.921493,
       lng: 12.337646,
    });

function loadMarkerTimeout(timeout) {
    setTimeout(loadMarker, timeout)
}

function loadMarker() { 
    map.setZoom(6);         
    $.ajax({
            url: [Insert here your URL] ,
            type:'POST',
            data: {
                "action":   "loadMarker"
            },
            success:function(result){

                /***************************
                 * Assuming your ajax call
                 * return something like: 
                 *   array(
                 *      'status' => 'success',
                 *      'results'=> $resultsArray
                 *   );
                 **************************/

                var res=JSON.parse(result);
                if(res.status == 'success') {
                    resNumber = res.results.length;
                    //Call the geoCoder function
                    getGeoCodeFor(map, res.results);
                }
            }//success
    });//ajax
};//loadMarker()

$().ready(function(e) {
  loadMarker();
});

//Geocoder function
function getGeoCodeFor(maps, addresses) {
        $.each(addresses, function(i,e){                
                GMaps.geocode({
                    address: e.address,
                    callback: function(results, status) {
                            geocode_count++;        

                            if (status == 'OK') {       

                                //if the element is alreay in the array, remove it
                                lost_addresses = jQuery.grep(lost_addresses, function(value) {
                                    return value != e;
                                });


                                latlng = results[0].geometry.location;
                                map.addMarker({
                                        lat: latlng.lat(),
                                        lng: latlng.lng(),
                                        title: 'MyNewMarker',
                                    });//addMarker
                            } else if (status == 'ZERO_RESULTS') {
                                //alert('Sorry, no results found');
                            } else if(status == 'OVER_QUERY_LIMIT') {

                                //if the element is not in the losts_addresses array, add it! 
                                if( jQuery.inArray(e,lost_addresses) == -1) {
                                    lost_addresses.push(e);
                                }

                            } 

                            if(geocode_count == addresses.length) {
                                //set counter == 0 so it wont's stop next round
                                geocode_count = 0;

                                setTimeout(function() {
                                    getGeoCodeFor(maps, lost_addresses);
                                }, 2500);
                            }
                    }//callback
                });//GeoCode
        });//each
};//getGeoCodeFor()

Пример:

map = new GMaps({
  div: '#gmap_marker',
  lat: 43.921493,
  lng: 12.337646,
});

var jsonData = {  
   "status":"success",
   "results":[  
  {  
     "customerId":1,
     "address":"Via Italia 43, Milano (MI)",
     "customerName":"MyAwesomeCustomer1"
  },
  {  
     "customerId":2,
     "address":"Via Roma 10, Roma (RM)",
     "customerName":"MyAwesomeCustomer2"
  }
   ]
};
			
function loadMarkerTimeout(timeout) {
  setTimeout(loadMarker, timeout)
}

function loadMarker() {	
  map.setZoom(6);
 
  $.ajax({
    url: '/echo/html/',
    type: "POST",
    data: jsonData,
    cache: false,
    success:function(result){

      var res=JSON.parse(result);
      if(res.status == 'success') {
        resNumber = res.results.length;
        //Call the geoCoder function
        getGeoCodeFor(map, res.results);
      }
    }//success
  });//ajax
  
};//loadMarker()

$().ready(function(e) {
  loadMarker();
});

//Geocoder function
function getGeoCodeFor(maps, addresses) {
  $.each(addresses, function(i,e){				
    GMaps.geocode({
      address: e.address,
      callback: function(results, status) {
        geocode_count++;		
        
        console.log('Id: '+e.customerId+' | Status: '+status);
        
        if (status == 'OK') {		

          //if the element is alreay in the array, remove it
          lost_addresses = jQuery.grep(lost_addresses, function(value) {
            return value != e;
          });


          latlng = results[0].geometry.location;
          map.addMarker({
            lat: latlng.lat(),
            lng: latlng.lng(),
            title: e.customerName,
          });//addMarker
        } else if (status == 'ZERO_RESULTS') {
          //alert('Sorry, no results found');
        } else if(status == 'OVER_QUERY_LIMIT') {

          //if the element is not in the losts_addresses array, add it! 
          if( jQuery.inArray(e,lost_addresses) == -1) {
            lost_addresses.push(e);
          }

        } 

        if(geocode_count == addresses.length) {
          //set counter == 0 so it wont's stop next round
          geocode_count = 0;

          setTimeout(function() {
            getGeoCodeFor(maps, lost_addresses);
          }, 2500);
        }
      }//callback
    });//GeoCode
  });//each
};//getGeoCodeFor()
#gmap_marker {
  min-height:250px;
  height:100%;
  width:100%;
  position: relative; 
  overflow: hidden;
 }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://maps.google.com/maps/api/js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gmaps.js/0.4.24/gmaps.min.js" type="text/javascript"></script>


<div id="gmap_marker"></div> <!-- /#gmap_marker -->

26
ответ дан Community 15 August 2018 в 19:14
поделиться
  • 1
    Спасибо geocodezip. Я попытался отложить его с помощью window.setTimeout, но он работал только с задержкой в ​​1 секунду. Теперь я изменил код, чтобы я выдавал запросы на геокодирование, пока не получаю ответ OVER_QUERY_LIMIT. После этого я делаю паузу в течение 3 секунд, а затем повторяю. Кажется, что эта стратегия разрешает 50 запросов примерно за 26 секунд (а не 50 секунд). Я все уши, если есть лучшая стратегия. – user544192 24 December 2012 в 06:44
26
ответ дан Community 5 September 2018 в 18:27
поделиться

Часто, когда вам нужно показать так много точек на карте, вам лучше использовать серверный подход, в этой статье объясняется, когда использовать каждый:

Стратегии геокодирования: https://developers.google.com/maps/articles/geocodestrat

Предел на стороне клиента не соответствует «10 запросам в секунду», и поскольку он не объясняется в документах API Я не стал бы полагаться на его поведение.

4
ответ дан miguev 15 August 2018 в 19:14
поделиться
Другие вопросы по тегам:

Похожие вопросы: