我正在處理此地圖並試圖對150個標記進行地理編碼,但是我正在點擊地理編碼限制。如何添加時間延遲以避免達到上限?將時間延遲添加到Google地圖地理編碼
1
A
回答
2
這爲地理編碼添加了一個計時器,因此每個標記都有延遲。
// Adding a LatLng object for each city
function geocodeAddress(i) {
geocoder.geocode({'address': address[i]}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
places[i] = results[0].geometry.location;
// Adding the markers
var marker = new google.maps.Marker({position: places[i], map: map});
markers.push(marker);
mc.addMarker(marker);
// Creating the event listener. It now has access to the values of i and marker as they were during its creation
google.maps.event.addListener(marker, 'click', function() {
// Check to see if we already have an InfoWindow
if (!infowindow) {
infowindow = new google.maps.InfoWindow();
}
// Setting the content of the InfoWindow
infowindow.setContent(popup_content[i]);
// Tying the InfoWindow to the marker
infowindow.open(map, marker);
});
// Extending the bounds object with each LatLng
bounds.extend(places[i]);
// Adjusting the map to new bounding box
map.fitBounds(bounds)
} else {
alert("Geocode was not successful for the following reason: " + status);
}
})
}
function geocode() {
if (geoIndex < address.length) {
geocodeAddress(geoIndex);
++geoIndex;
}
else {
clearInterval(geoTimer);
}
}
var geoIndex = 0;
var geoTimer = setInterval(geocode, 200); // 200 milliseconds (to try out)
var markerCluster = new MarkerClusterer(map, markers);
}
})
();
</script>
ADDED。上述程序可以調整。
(1)可減少的時間間隔:
var geoTimer = setInterval(geocode, 100); // do requests each 100 milliseconds
(2)函數的地址解析()可以在每個時間間隔執行若干請求,例如5請求:
function geocode() {
for (var k = 0; k < 5 && geoIndex < address.length; ++k) {
geocodeAddress(geoIndex);
++geoIndex;
}
if (geoIndex >= address.length) {
clearInterval(geoTimer);
}
}
相關問題
- 1. Android在Google地圖上添加延遲地圖
- 2. 地理編碼API的延遲
- 3. 地圖Google地圖地理編碼器
- 4. 將Google地圖地理編碼API密鑰遷移到生產
- 5. 如何將延遲時間添加到JavaScript代碼行中
- 6. 將Kml圖層添加到Google地圖
- 7. 時間地圖和地圖抽象地理編碼
- 8. 將風格添加到Angular2 Google地圖
- 9. 在地圖視圖中延遲加載?
- 10. 將參數添加到谷歌地圖地理編碼器函數
- 11. 如何將徽標添加到谷歌地圖地理編碼api
- 12. 處理環境 - 延遲時間延遲
- 13. 將標記延遲加載到Google Maps JavaScript API地圖的策略
- 14. Google Maps API地理編碼
- 15. Google地理編碼API「OVER_QUERY_LIMIT」
- 16. 以編程方式將明星添加到Google地圖帳戶
- 17. 以編程方式將點添加到Google Drive的地圖
- 18. 在Google地圖API中對IP地址進行地理編碼
- 19. 使用地理編碼將多個addListener事件添加到Google Map表單
- 20. Bing地理編碼與Google地理編碼的使用限制?
- 21. SQL |將Google地圖網址轉換爲滯後和延遲
- 22. 將Google「我的地圖」圖層添加到Google Maps JavaScript API
- 23. 如何添加時間延遲
- 24. 在Python中添加multipe時間延遲
- 25. 給JQuery函數添加時間延遲?
- 26. 如何將外部值添加到Leaflet地理編碼查詢?
- 27. 僅在需要時纔將標記添加到Google地圖
- 28. 將時間延遲圖像追加到視頻文件
- 29. 谷歌地圖/地點地理編碼
- 30. 將JSON加載到時間地圖
如果您只提供不帶PHP的Javascript代碼,尤其是當您希望將答案合併到您的代碼中時,將會有所幫助。 – Jiri
@Jiri通過查看提供的鏈接的來源可以很容易地找到它。由於其他方面與之前的php發生衝突,我已經將其包含在內。 – Rob