我做了一个谷歌地图有x个不同的引脚。当我将鼠标悬停在一个pin上时,我可以看到html代码:
['Company a<br>\
Address x, Dk-2750 <br>\
<a href="#">Show way</a>
我已经尝试设置标题和标签,所以我可以选择文本应该是什么时候悬停在一个引脚。有谁知道我怎么能在一个别针上钉上一个标签?
<script>
function initMap() {
var center = {lat: 56.2639, lng: 9.5018};
var locations = [
['Company a<br>\
Address x, Dk-2750 <br>\
<a href="#" alt>Show way</a>', 55.730097, 12.375905],
['Company b<br>\
Address y, Dk-6600<br>\
<a href="#">Show way</a>', 55.769726, 12.497519],
['Company c<br>\
Address z, Dk-6950<br>\
<a href="#">Show way</a>', 56.110692, 8.322713],
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 7,
center: center
});
var infowindow = new google.maps.InfoWindow({});
var marker, count;
for (count = 0; count < locations.length; count++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[count][1], locations[count][2]),
map: map,
title: locations[count][0]
});
google.maps.event.addListener(marker, 'click', (function (marker, count) {
return function () {
infowindow.setContent(locations[count][0]);
infowindow.open(map, marker);
}
})(marker, count));
}
}
</script>