这是我的多个标记的代码: https://docs.google.com/document/d/1IeKxEhA0M4ggzO8ENvKvHYG2Z1CIBH8WthcwJYxc6aU/pub
我需要点击标记show infowindow ...
有一个例子我想要它但我需要它到我的不同脚本... https://developers.google.com/maps/documentation/javascript/examples/infowindow-simple
THX
答案 0 :(得分:0)
您可以为标记创建一个全局数组:您在setMarkers()函数中定义了每个数组,如下所示:
for (var i = 0; i < locations.length; i++) {
var beach = locations[i];
var myLatLng = new google.maps.LatLng(beach[1], beach[2]);
markers[i] = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image,
shape: shape,
title: beach[0],
zIndex: beach[3]
});
}
然后你创建了你的信息窗口:
var markers = new Array();
function initialize() {
var mapOptions = {
zoom: 7,
center: new google.maps.LatLng(48.864372, 19.311537)
}
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
setMarkers(map, beaches);
for(i = 0; i < markers.length; i++){
var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">Uluru</h1>'+
'<div id="bodyContent">'+
'<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
'sandstone rock formation in the southern part of the '+
'Northern Territory, central Australia. It lies 335 km (208 mi) '+
'south west of the nearest large town, Alice Springs; 450 km '+
'(280 mi) by road. Kata Tjuta and Uluru are the two major '+
'features of the Uluru - Kata Tjuta National Park. Uluru is '+
'sacred to the Pitjantjatjara and Yankunytjatjara, the '+
'Aboriginal people of the area. It has many springs, waterholes, '+
'rock caves and ancient paintings. Uluru is listed as a World '+
'Heritage Site.</p>'+
'<p>Attribution: Uluru, <a href="http://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
'http://en.wikipedia.org/w/index.php?title=Uluru</a> '+
'(last visited June 22, 2009).</p>'+
'</div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
google.maps.event.addListener(markers[i], 'click', function() {
infowindow.open(map, markers[i]);
});
}
}