2012-12-23 13 views
20

मैं मानचित्र पर लगभग 50 स्थानों को प्रदर्शित करने के लिए Google मानचित्र API का उपयोग कर रहा हूं। मैं क्लाइंट साइड जियोकोडिंग का उपयोग कर रहा हूं। मैं प्रति सेकंड भेजता है कि geocode अनुरोधों की संख्या को नियंत्रित करने के लिए window.setTimeout का उपयोग कर रहा हूँ। यदि मैं प्रति सेकंड 1 से अधिक अनुरोध भेजता हूं, तो मुझे बहुत अधिक प्रतिक्रिया मिल रही है।Google मानचित्र एपीआई प्रति सेकंड सीमा से अधिक सीमा

प्रश्न: क्या यह सीमा प्रति सेकंड 10 प्रश्न नहीं होने चाहिए? यदि हां, तो मैं गलत क्या कर सकता हूं? यदि नहीं, तो क्या बिजनेस एपीआई में प्रति सेकंड सीमा अधिक उदार प्रश्न हैं?

कृपया ध्यान दें कि हमारा आवेदन प्रति दिन 25,000 प्रश्नों को मारने वाला नहीं है।

+0

आप जियोकोडिंग सर्वर कैसे जानना चाहते हैं? कुछ कोड दिखाएं – keune

+0

यहाँ देखो: http://stackoverflow.com/questions/16659398/google-maps-over-query-limit की – user2403424

+0

संभावित डुप्लिकेट [अधिक \ _QUERY \ _LIMIT जबकि गूगल मैप्स का उपयोग कर] (http: // stackoverflow .com/प्रश्न/3529746/ओवर-क्वेरी-सीमा-जबकि-उपयोग-google-maps) – xomena

उत्तर

25

जिओकोडर कोटा और दर सीमाएं हैं। अनुभव से, आप क्वेरी सीमा को मारने के बिना ~ 10 स्थानों को geocode कर सकते हैं (वास्तविक संख्या शायद सर्वर लोडिंग पर निर्भर करता है)। जब आप OVER_QUERY_LIMIT त्रुटियां प्राप्त करते हैं तो सबसे अच्छा समाधान देरी होती है, फिर पुनः प्रयास करें।

+4

धन्यवाद geocodezip। मैंने window.setTimeout का उपयोग करके इसे देरी करने का प्रयास किया लेकिन यह केवल 1 सेकंड की देरी के साथ काम करता था।अब, मैंने कोड बदल दिया है ताकि जब तक मैं OVER_QUERY_LIMIT प्रतिक्रिया प्राप्त नहीं करता तब तक मैं geocode अनुरोध जारी करता हूं। उसके बाद मैं 3 सेकंड के लिए रुकता हूं और फिर दोहराता हूं। यह रणनीति लगभग 26 सेकंड (50 सेकंड के बजाय) में 50 अनुरोधों को हल करने लगती है। यदि कोई बेहतर रणनीति है तो मैं सभी कान हूं। – user544192

4

अक्सर जब आप नक्शे पर इतने सारे अंक दिखाने की जरूरत है, तो आप सर्वर साइड का उपयोग कर बेहतर होगा: इन समान पोस्ट देखें दृष्टिकोण, यह आलेख बताता है कि प्रत्येक का उपयोग कब करें:

जियोकोडिंग रणनीतियां: https://developers.google.com/maps/articles/geocodestrat

क्लाइंट-साइड सीमा बिल्कुल "प्रति सेकंड 10 अनुरोध" नहीं है, और चूंकि इसे एपीआई दस्तावेज़ों में समझाया नहीं गया है, इसलिए मैं इसके व्यवहार पर भरोसा नहीं करता।

1

यह दृष्टिकोण Google सर्वर अधिभार का सही उपयोग नहीं है। अधिक जानकारियां के लिए, देखें https://gis.stackexchange.com/questions/15052/how-to-avoid-google-map-geocode-limit#answer-15365


वैसे अगर आप फिर भी जारी रखना चाहते हैं, तो यहां आपको एक कोड आप एकाधिक मार्करों ajax गूगल मैप्स OVER_QUERY_LIMIT त्रुटि से बचने के स्रोत लोड है कि मिल सकता है।

मैंने अपने ऑनव सर्वर पर परीक्षण किया है और यह काम करता है!:

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" 
 
    } 
 
    ] 
 
}; 
 
\t \t \t 
 
function loadMarkerTimeout(timeout) { 
 
    setTimeout(loadMarker, timeout) 
 
} 
 

 
function loadMarker() { \t 
 
    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){ \t \t \t \t 
 
    GMaps.geocode({ 
 
     address: e.address, 
 
     callback: function(results, status) { 
 
     geocode_count++; \t \t 
 
     
 
     console.log('Id: '+e.customerId+' | Status: '+status); 
 
     
 
     if (status == 'OK') { \t \t 
 

 
      //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 -->

0
Here I have loaded 2200 markers. It takes around 1 min to add 2200 locations. 
<https://jsfiddle.net/suchg/qm1pqunz/11/> 


Hope it would help you. 
+0

अरे क्या आपके पास कोई विचार है कि INVALID_REQUEST के मामले में कैसे छोड़ा जाए? – hyperfkcb