开发者

Missing dynamic Markers GMaps V3

I have written some code to fetch zipcodes from a mysql db via ajax call, geocode them, then make markers out of them on a GMap. The markers are clickable to reveal some demographic data. It works if i leave the alert in the each loop uncommented. If not it only shows about 8 markers. Any and all help is appreciated. Relevant code:

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 
                            });
                        开发者_StackOverflow中文版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);
}


Google Geocoding API has both query and rate limits. You need to slow down when querying.

Use of the Google Geocoding API is subject to a query limit of 2,500 geolocation requests per day.

Additionally, we enforce a request rate limit to prevent abuse of the service.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜