Ajax 缺少动态标记GMAPSv3
我已经编写了一些代码,通过ajax调用从mysql数据库获取zipcodes,对它们进行地理编码,然后在GMap上对它们进行标记。点击标记可以显示一些人口统计数据。如果我将each循环中的警报保持为未注释状态,则它会起作用。如果没有,它只显示大约8个标记。非常感谢您的帮助。相关代码:Ajax 缺少动态标记GMAPSv3,ajax,google-maps,Ajax,Google Maps,我已经编写了一些代码,通过ajax调用从mysql数据库获取zipcodes,对它们进行地理编码,然后在GMap上对它们进行标记。点击标记可以显示一些人口统计数据。如果我将each循环中的警报保持为未注释状态,则它会起作用。如果没有,它只显示大约8个标记。非常感谢您的帮助。相关代码: function initialize() { var geocoder = new google.maps.Geocoder(); var markers = []; var latlng = new googl
function initialize() {
var geocoder = new google.maps.Geocoder();
var markers = [];
var latlng = new google.maps.LatLng("33.7463915", "-117.86044720000001");
var myOptions = {
zoom: 11,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
$.ajax({
url: 'getzips.php',
dataType: 'json',
success: function (data) {
$.each(data.rows, function(i, item) {
//alert(item.zip);
if (geocoder) {
geocoder.geocode({ 'address': item.zip }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latlng = new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng());
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: item.zip
});
var infowindow = new google.maps.InfoWindow({
content: item.zip
});
google.maps.event.addListener(marker, "click", function() {
$.ajax({
url: 'getinfo.php?zipcode=' + marker.title,
success: function(data){
infowindow.setContent(data);
infowindow.open(map, marker);
}
});
});
markers.push(marker);
}
});
}
else
alert("geocode error");
});
}
});
//alert(markers.length);
}
谷歌地理编码API有查询和速率限制。查询时需要放慢速度 谷歌地理编码API的使用受限于每天2500个地理定位请求的查询限制 此外,我们强制执行请求速率限制以防止滥用服务
太棒了,谢谢!我会把所有我需要的拉链编上地理编码,然后储存起来。