/ Published in: JavaScript
use http://code.google.com/apis/ajax/playground/?exp=maps#map_markers to play with this code
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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}); }); } } }