How to use onOpenFn in GMap


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. function initialize() {
  2. if (GBrowserIsCompatible()) {
  3. var map = new GMap2(document.getElementById("map_canvas"));
  4. map.setCenter(new GLatLng(37.4419, -122.1419), 13);
  5.  
  6. // Add 10 markers to the map at random locations
  7. var bounds = map.getBounds();
  8. var southWest = bounds.getSouthWest();
  9. var northEast = bounds.getNorthEast();
  10. var lngSpan = northEast.lng() - southWest.lng();
  11. var latSpan = northEast.lat() - southWest.lat();
  12. for (var i = 0; i < 10; i++) {
  13. var point = new GLatLng(southWest.lat() + latSpan * Math.random(),
  14. southWest.lng() + lngSpan * Math.random());
  15. var marker = new GMarker(point);
  16. map.addOverlay(marker);
  17.  
  18. GEvent.addListener(marker, "click", function() {
  19. var openFnCallback = function() {alert('hello');};
  20. // remember! not marker, we can only use map for onOpenFn/onCloseFn
  21. map.openInfoWindowHtml(point, 'hello ' + point,{onOpenFn: openFnCallback});
  22. });
  23. }
  24. }
  25. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.