views:

14

answers:

1

I used this code but its not working.

function initialize() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(10.35,79.4167), 13);
    var marker = new GMarker(new GLatLng(10.35,79.4167));
     map.setCenter(new GLatLng(8.7167,77.483), 14);
    var marker = new GMarker(new GLatLng(8.7167,77.483));
     map.setCenter(new GLatLng(21.83,78.75), 15);
    var marker = new GMarker(new GLatLng(21.83,78.75));
     map.addOverlay(marker);

    map.setUIToDefault();
  }
}
+1  A: 

Your code will only add the last marker. You are only calling addOverlay once at the end (so only the last marker will be added to the map).

You also call setCenter multiple times, so only the last setCenter will be applied to the map. setCenter just sets the visible area on the Google Map.

You are using Google Maps v2 in your code, I suggest you check out the more current v3 API. If you are starting a new project, you may as well use the latest stuff.

If you have some other reason for using the v2 API, there is a range of good samples to get you started.

Cannonade