How to plot multiple points on a map using google maps

The following source code can be used to plot multiple points on a map using google maps api.

Javascript :

var locations = [
    ['Bondi Beach', -33.890542, 151.274856, 4],
    ['Coogee Beach', -33.923036, 151.259052, 5],
    ['Cronulla Beach', -34.028249, 151.157507, 3],
    ['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
    ['Maroubra Beach', -33.950198, 151.259302, 1]
];
var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 10,
    center: new google.maps.LatLng(-33.92, 151.25),
    mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
    marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map
    });
    google.maps.event.addListener(marker, 'click', (function (marker, i) {
        return function () {
            infowindow.setContent(locations[i][0]);
            infowindow.open(map, marker);
        }
    })(marker, i));
}

HTML content :

<div id="map" style="width: 500px; height: 400px;"></div>

Remember to include the following script at the head section :

<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>

If you have followed the above steps then you will get something like the image below :

multimarkers
Cheers.

3 Comments on "How to plot multiple points on a map using google maps"


  1. Beneficial info. Lucky me personally I ran across your internet site inadvertently, for shocked why this particular chance decided not to taken place beforehand! My spouse and i saved the item.

    Reply

  2. I comment when I like a post on a site or
    if I have something to add to the discussion. It is a result of the passion displayed in the
    article I browsed. And after this article How
    to plot multiple points on a map using google maps
    | Web Development Tips & Tricks. I was actually moved enough to
    post a leave a responsea response 😉 I do have a couple of questions for
    you if you don’t mind. Could it be only me or does
    it seem like some of these remarks appear as if they are left by brain dead people?
    😛 And, if you are writing at additional online social sites, I would like to
    keep up with you. Could you list every one of all your public pages like your linkedin profile, Facebook page
    or twitter feed?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *