以下代码在map上创建了一个Marker,然后在Marker上注册了事件监听器,点击后显示了InfoWindow.
// Creating an option object for the map var options = { zoom: 7, center: new google.maps.LatLng(56.83, 15.16), mapTypeId: google.maps.MapTypeId.ROADMAP }; // Initializing the map var map = new google.maps.Map(document.getElementById('map'), options); // Creating a marker var marker = new google.maps.Marker({ position: new google.maps.LatLng(56.8848, 14.7730), map: map, title: 'My workplace' }); // Creating an InfoWindow object var infowindow = new google.maps.InfoWindow({ content: 'Hello world' }); google.maps.event.addListener(marker, 'click', function() { infowindow.open(map, marker); });
via:http://www.svennerberg.com/2009/09/google-maps-api-3-infowindows/