32

Google Maps APIを使用して、地図上に約50の場所を表示しています。クライアント側のジオコーディングを使用しています。window.setTimeoutを使用して、アプリケーションが1秒あたりに送信する地理コード要求の数を制御しています。1秒間に複数のリクエストを送信すると、OVERQUERYLIMIT応答が返されます。

質問:この制限は1秒あたり10クエリであると想定されていませんか?はいの場合、私は何を間違っている可能性がありますか?いいえの場合、Business APIには1秒あたりのクエリ数の制限がありますか?

私たちのアプリケーションは1日あたり25,000クエリに達することはないことに注意してください。

4

4 に答える 4

32

ジオコーダーには、割り当てとレートの制限があります。経験から、クエリの制限に達することなく最大10の場所をジオコーディングできます(実際の数はおそらくサーバーの負荷によって異なります)。最善の解決策は、OVER_QUERY_LIMITエラーが発生したときに遅延してから、再試行することです。これらの同様の投稿を参照してください:

于 2012-12-23T20:35:11.923 に答える
5

多くの場合、地図上に非常に多くのポイントを表示する必要がある場合は、サーバー側のアプローチを使用する方がよいでしょう。この記事では、それぞれをいつ使用するかについて説明します。

ジオコーディング戦略:https ://developers.google.com/maps/articles/geocodestrat

クライアント側の制限は正確には「1秒あたり10リクエスト」ではなく、APIドキュメントで説明されていないため、その動作に依存しません。

于 2012-12-27T09:36:37.990 に答える
1

Googleサーバーの過負荷のため、このアプローチは正しくありません。詳細については、 https://gis.stackexchange.com/questions/15052/how-to-avoid-google-map-geocode-limit#answer-15365を参照してください。


ちなみに、とにかく続行したい場合は、ここで、OVER_QUERY_LIMITエラーを回避してグーグルマップで供給された複数のマーカーajaxをロードできるようにするコードを見つけることができます。

私は自分の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 -->

于 2016-10-04T14:32:34.830 に答える
0

クライアント側のジオコーディングの代わりに

geocoder.geocode({
    'address': your_address
  }, function (results, status) {
     if (status == google.maps.GeocoderStatus.OK) {
       var geo_data = results[0];
       // your code ...
   } 
})

サーバーサイドのジオコーディングAPIに行きます

var apikey = YOUR_API_KEY;
var query = 'https://maps.googleapis.com/maps/api/geocode/json?address=' + address + '&key=' + apikey;
$.getJSON(query, function (data) {
  if (data.status === 'OK') { 
    var geo_data = data.results[0];
  } 
})
于 2019-02-24T02:11:28.180 に答える