我使用标准Google Maps API v3制作包含多个图钉的地图。
我想知道是否有办法让我联系这个popop:
示例:用户单击地图图钉,会加载此工具提示,他们可以点击工具提示(作为链接)以获取更多信息。
以下是我如何生成地图:
var locations = [
['Bondi Beach', -33.890542, 151.274856, 4],
['Coogee Beach', -33.923036, 151.259052, 5],
['Cronulla Beach', -34.028249, 151.157507, 3],
['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
['Maroubra Beach', -33.950198, 151.259302, 1]
];
var map = new google.maps.Map(document.getElementById('mapFrame123'), {
zoom: 10,
center: new google.maps.LatLng(-33.890542, 151.274856),
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
});
console.log(marker);
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
有什么想法吗?
答案 0 :(得分:1)
您可以将HTML内容放入infowindows。您没有指定要链接的内容,但您可以执行以下操作:
var locations = [
['Bondi Beach', -33.890542, 151.274856, 4, 'http://bondi.com'],
['Coogee Beach', -33.923036, 151.259052, 5, 'http://coogee.com'],
['Cronulla Beach', -34.028249, 151.157507, 3, 'http://cronulla.com'],
['Manly Beach', -33.80010128657071, 151.28747820854187, 2, 'http://manly.com'],
['Maroubra Beach', -33.950198, 151.259302, 1, 'http://maroubra.com']
];
...
infowindow.setContent('<a href="' + locations[i][4] + '">' + locations[i][0] + '</a>');