2012-12-23 92 views
20

Tôi đang sử dụng API Google Maps để hiển thị khoảng 50 vị trí trên bản đồ. Tôi đang sử dụng mã hóa địa lý phía máy khách. Tôi đang sử dụng window.setTimeout để kiểm soát số lượng yêu cầu mã địa lý mà ứng dụng gửi mỗi giây. Nếu tôi gửi nhiều hơn 1 yêu cầu mỗi giây, tôi nhận được phản hồi TRÊN GIỚI HẠN.API Google Maps OVER QUERY LIMIT mỗi giới hạn thứ hai

Câu hỏi: Giới hạn này có phải là 10 truy vấn mỗi giây không? Nếu có, thì tôi có thể làm gì sai? Nếu không, thì Business API có các truy vấn rộng rãi hơn cho mỗi giới hạn thứ hai không?

Xin lưu ý rằng ứng dụng của chúng tôi sẽ không đạt tới 25.000 truy vấn mỗi ngày.

+0

How are you truy vấn máy chủ mã hóa địa lý? Hiển thị một số mã. – keune

+0

Nhìn đây: http://stackoverflow.com/questions/16659398/google-maps-over-query-limit – user2403424

+0

thể trùng lặp của [VỀ \ _QUERY \ _LIMIT khi sử dụng bản đồ google] (http: // stackoverflow .com/questions/3529746/over-query-limit-while-using-google-maps) – xomena

Trả lời

25

Bộ mã hóa địa lý có giới hạn tốc độ và giới hạn. Từ kinh nghiệm, bạn có thể mã hóa địa lý ~ 10 vị trí mà không cần nhấn giới hạn truy vấn (số thực tế có thể phụ thuộc vào tải máy chủ). Giải pháp tốt nhất là trì hoãn khi bạn nhận được OVER_QUERY_LIMIT lỗi, sau đó thử lại. Xem các bài viết tương tự:

+4

Cảm ơn mã hóa địa lý. Tôi đã cố gắng trì hoãn nó bằng cách sử dụng window.setTimeout nhưng nó chỉ làm việc với một sự chậm trễ 1 giây.Bây giờ, tôi đã thay đổi mã để tôi đưa ra yêu cầu mã địa lý cho đến khi tôi nhận được phản hồi OVER_QUERY_LIMIT. Sau đó tôi tạm dừng trong 3 giây và sau đó lặp lại. Chiến lược này dường như giải quyết 50 yêu cầu trong khoảng 26 giây (thay vì 50 giây). Tôi là tất cả các tai nếu có một chiến lược tốt hơn. – user544192

4

Thông thường khi bạn cần phải chứng minh rất nhiều điểm trên bản đồ, bạn muốn được tốt hơn bằng cách sử dụng server-side tiếp cận, bài viết này giải thích thời điểm sử dụng mỗi:

Chiến lược mã hóa địa lý: https://developers.google.com/maps/articles/geocodestrat

Giới hạn phía máy khách không chính xác là "10 yêu cầu mỗi giây" và vì nó không được giải thích trong tài liệu API, tôi sẽ không dựa vào hành vi của nó.

1

Cách tiếp cận này không đúng khi sử dụng Quá tải máy chủ của Google. Đối với nhiều thông tin thấy https://gis.stackexchange.com/questions/15052/how-to-avoid-google-map-geocode-limit#answer-15365


By the way, nếu bạn muốn tiếp tục dù sao, ở đây các bạn có thể tìm thấy một mã số cho phép bạn tải nhiều dấu ajax nguồn gốc trên bản đồ google tránh lỗi OVER_QUERY_LIMIT.

Tôi đã thử nghiệm trên máy chủ onw của mình và nó hoạt động!:

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() 

Ví dụ:

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

Bạn có ý tưởng nào về cách bỏ qua trong trường hợp INVALID_REQUEST không? – hyperfkcb

Các vấn đề liên quan