Skip to content Skip to sidebar Skip to footer

How To Define Multiple Locations Using Google Maps Api To Drop Pin For Every Post In A List Of Posts Generated By A Loop

This question might be answered in other posts, but I haven't found the specific answer and I'm having trouble discerning how to logically think through this. I have a site where e

Solution 1:

You need to add markers in a loop. this was taken from a project i was working.

var locations = ["Denver, CO, United States"];
var markers = [];
var iterator = 0;

for (var i = 0; i < locations.length; i++) {
    setTimeout(function() {
            geocoder.geocode({'address': locations[iterator]}, function(results, status){
        if (status == google.maps.GeocoderStatus.OK) {
            var marker = new google.maps.Marker({
                map: map,
                position: results[0].geometry.location,
                animation: google.maps.Animation.DROP
            });
            bounds.extend(marker.getPosition());
            map.fitBounds(bounds);
        } else {
            log('Geocode was not successful for the following reason: ' + status);
        }
    });
    iterator++;

    }, i * 250);
}

Post a Comment for "How To Define Multiple Locations Using Google Maps Api To Drop Pin For Every Post In A List Of Posts Generated By A Loop"