[英]javascript google maps API - change title of marker
我正在嘗試在Google地圖標記圖標上填充小的注釋。 標題似乎沒有做到。 我閱讀了文檔,但找不到任何東西。
https://developers.google.com/maps/documentation/javascript/examples/marker-labels
var marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i]["lat"], locations[i]["lng"]),
map: map,
title: "a title here"
});
現在,即使已設置注釋的標題,注釋仍為空白。 我從來沒有弄清楚標題的實際用途,因為標簽是圖標中字符的標題,標題對注釋沒有影響。
您可以使用標記填充文本標記的屬性是什么?
編輯:謝謝塞繆爾·托。
這是我最終使用的工作代碼:
var locations;// use this as the array which holds the data
for (i = 0; i < locations.length; i++) {
about the locations you are adding to the map
var marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i]["lat"], locations[i]["lng"]),
map: map,
title: activities[i]["city"]
});
//extend the bounds to include each markers position
bounds.extend(marker.position);
google.maps.event.addListener(marker, "click", (function(marker, i) {
return function() {
infowindow.setContent(locations[i]["city"]);
infowindow.open(map, marker);
}
})(marker, i));
}
您需要一個infoWindow
對象來顯示標題文本。
請參閱: https : //developers.google.com/maps/documentation/javascript/examples/infowindow-simple
var infowindow = new google.maps.InfoWindow({
content: "<span>any html goes here</span>" });
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: 'Uluru (Ayers Rock)' });
google.maps.event.addListener(marker, 'click', function() { infowindow.open(map,marker); });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.