Return to Snippet

Revision: 14178
at May 22, 2009 02:35 by neofreko


Initial Code
function initialize() {
  if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(37.4419, -122.1419), 13);

    // Add 10 markers to the map at random locations
    var bounds = map.getBounds();
    var southWest = bounds.getSouthWest();
    var northEast = bounds.getNorthEast();
    var lngSpan = northEast.lng() - southWest.lng();
    var latSpan = northEast.lat() - southWest.lat();
    for (var i = 0; i < 10; i++) {
      var point = new GLatLng(southWest.lat() + latSpan * Math.random(),
                              southWest.lng() + lngSpan * Math.random());
      var marker = new GMarker(point);
      map.addOverlay(marker);

      GEvent.addListener(marker, "click", function() {
           var openFnCallback = function() {alert('hello');};
           // remember! not marker, we can only use map for onOpenFn/onCloseFn
           map.openInfoWindowHtml(point, 'hello ' + point,{onOpenFn: openFnCallback});
      });        
    }
  }
}

Initial URL

                                

Initial Description
use http://code.google.com/apis/ajax/playground/?exp=maps#map_markers to play with this code

Initial Title
How to use onOpenFn in GMap

Initial Tags

                                

Initial Language
JavaScript