小总结。由于地理编码不允许大量同时请求并且我必须在我的 googlemap 上显示超过 11 个标记,我想我会使用某种间隔来绕过同时请求限制。
我想在这里我会使用 javascript 中的 setInterval 函数。
这是我的代码
function timeHackGeocode(location, name, contract, vestigingID)
{
setInterval(codeAddress(location, name, contract, vestigingID), 1000);
}
function collectingData() {
@foreach (var item in Model) {
@:timeHackGeocode("@item.StraatVestiging" + " " + "@item.nr" + "," + "@item.location","@item.name","@item.Contract", "@item.id");
}
}
function codeAddress(location, name, contract, vestigingID) {
var address = location;
var image;
var zoomlevel;
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var infoboxPos = results[0].geometry.location;
var image = new google.maps.MarkerImage(returnImage(contract),
// This marker is 20 pixels wide by 32 pixels tall.
new google.maps.Size(30, 42),
// The origin for this image is 0,0.
new google.maps.Point(40,45),
// The anchor for this image is the base of the flagpole at 0,32.
new google.maps.Point(0, 32));
var marker = createMarkers(results[0].geometry.location, contract)
google.maps.event.addListener(marker, 'mouseover', function() {
infobox.open(map, marker);
infobox.setOptions(infoboxOptions(boxText(name, contract, vestigingID), infoboxPos));
});
} else {
// alert("Geocode was not successful for the following reason: " + status);
}
});
}
不幸的是,这似乎不起作用,我尝试了各种不同的设置。 https://developer.mozilla.org/en/DOM/window.setInterval
有谁知道发生了什么?
附言。我将来会通过已经有了纬度和经度来改变这个黑客,但现在我希望让它发挥作用。
建议非常感谢。