Google map two markers on one map

Hey. I am trying to put two points on the same map with the same div id.
but it does not work.
the code:

for the 1st,

  var map = new GMap2(document.getElementById("map-canvas"));
  map.addControl(new GLargeMapControl());
  map.addControl(new GMapTypeControl());
  map.setCenter(new GLatLng(<?=$lat;?>,<?=$lng;?>), 6);

  var point = new GLatLng(<?=$lat;?>,<?=$lng;?>);
  var marker = createMarker(point,'Welcome:<b></b><br>Second Info Window with an image<br><img src="http://localhost/gps/user_photo/" width=80 height=80>')
  map.addOverlay(marker);


  function createMarker(point,html) {
        var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        return marker;
      }

for the second,

  var map = new GMap2(document.getElementById("map-canvas"));
  map.addControl(new GLargeMapControl());
  map.addControl(new GMapTypeControl());
  map.setCenter(new GLatLng(<?=$mylat;?>,<?=$mylng;?>), 6);

  var point1 = new GLatLng(<?=$mylat;?>,<?=$mylng;?>);
  var marker = createMarker1(point1,'Welcome:<b></b><br>Second Info Window with an image<br><img src="http://localhost/gps/user_photo/" width=80 height=80>')
  map.addOverlay(marker);


  function createMarker1(point,html) {
        var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        return marker;
      }

why are two points not shown on the same map ????? and it will be visible on two different maps ...

+5
source share
2 answers
  //set up map as before

  var point0 = new GLatLng(<?=$mylat0;?>,<?=$mylng0;?>);
  var point1 = new GLatLng(<?=$mylat1;?>,<?=$mylng1;?>);
  var marker0 = createMarker(point0,'Welcome:<b></b><br>First Info Window etc);
  var marker1 = createMarker(point1,'Welcome:<b></b><br>Second Info Window etc);
  map.addOverlay(marker);

// only declare this once
  function createMarker(point,html) {
        var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        return marker;
      }

This is one way to do this just to make it work for you, but essentially, the js dots and markers should be arrays that you are scrolling - maybe this is $ mylat and $ mylong vars in PHP.

+1
source
0

All Articles