GoogleMaps API v3 - 点击触发事件

时间:2014-08-20 15:54:27

标签: javascript jquery google-maps google-maps-api-3

这是我正在谈论的形象。

http://i.stack.imgur.com/jC2U2.jpg

我正在使用谷歌地图v3。

这是我迄今为止所做的事情的链接。任何帮助将不胜感激。

http://jsfiddle.net/ovmf1joe/4/

`function initialize() {
var locations = [
    ['<h4>Bondi Beach</h4>', -33.890542, 151.274856],
    ['<h4>Coogee Beach</h4>', -33.923036, 151.259052],
    ['<h4>Cronulla Beach</h4>', -34.028249, 151.157507],
    ['<h4>Manly Beach</h4>', -33.80010128657071, 151.28747820854187],
    ['<h4>Maroubra Beach</h4>', -33.950198, 151.259302]
  ];

   var map = new google.maps.Map(document.getElementById('mapContainer'), {
     zoom: 10,
     center: new google.maps.LatLng(-33.92, 151.25),
     mapTypeId: google.maps.MapTypeId.ROADMAP
   });

   var infowindow = new google.maps.InfoWindow();

   var marker, i;

   for (i = 0; i < locations.length; i++) {  
     marker = new google.maps.Marker({
       position: new google.maps.LatLng(locations[i][1], locations[i][2]),
       map: map
     });

     google.maps.event.addListener(marker, 'click', (function(marker, i) {
       return function() {
         infowindow.setContent(locations[i][0]);
         infowindow.open(map, marker);
       }
     })(marker, i));
   }
}
google.maps.event.addDomListener(window, 'load', initialize);


`

0 个答案:

没有答案