Rob*_*Rob 4 gis google-maps google-maps-api-3 google-maps-markers
我创建了一个包含大约150个标记的自定义地图.在它达到地理编码限制之前,它只绘制了大约20左右.
我可以将哪些内容合并到我的代码中以避免达到限制?
更新: 如何为每个请求添加时间延迟,例如0.25秒(或者我可以逃脱的最低值)?
我已经尝试了一些不同的建议,但我似乎无法让他们使用我的代码,所以请任何示例使用我的代码.
Jac*_*ble 19
因此,不是在for循环中几乎立即发送所有请求,我认为当地理编码返回结果时,发送下一个结果可能会更好.如果返回的结果是a OVER_QUERY_LIMIT,则重新发送请求并增加延迟.我没有找到产生最少的甜点超时OVER_QUERY_LIMIT,但至少它会创建所有标记(对于有效地址).在我的机器上完成大约需要45秒左右.
<!DOCTYPE html>
<html>
<head>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css"
rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var geocoder;
var map;
var infowindow = new google.maps.InfoWindow();
var places = [];
var popup_content = [ /* all your popup_content */];
var address = [/* all of your addresses */];
var address_position = 0;
var timeout = 600;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(52.40, -3.61);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: 'roadmap'
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
addMarker(address_position);
}
function addMarker(position)
{
geocoder.geocode({'address': address[position]}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK) {
places[position] = results[0].geometry.location;
var marker = new google.maps.Marker({
position: places[position],
map: map
});
google.maps.event.addListener(marker, 'click', function() {
if (!infowindow) {
infowindow = new google.maps.InfoWindow();
}
infowindow.setContent(popup_content[position]);
infowindow.open(map, marker);
});
}
else
{
if (status == google.maps.GeocoderStatus.OVER_QUERY_LIMIT)
{
setTimeout(function() { addMarker(position); }, (timeout * 3));
}
}
address_position++;
if (address_position < address.length)
{
setTimeout(function() { addMarker(address_position); }, (timeout));
}
});
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="height: 80%; top:10px; border: 1px solid black;"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10666 次 |
| 最近记录: |