2016-08-18 62 views
0

我想填充谷歌地圖標記圖標上的小標註。標題似乎並沒有這樣做。我閱讀了文檔,但找不到任何東西。javascript谷歌地圖API - 更改標記標題

enter image description herehttps://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" 


        }); 

眼下的註釋是空白的,即使對於註釋,標題被設定。我從來沒有想過標題實際用於哪一種,因爲標籤是用於圖標內的字符,標題對註釋沒有影響。

您可以用文本填充註釋的標記屬性是什麼?

編輯: 謝謝Samuel Toh。

這裏是工作的代碼,我最終使用:

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)); 
} 

回答

1

你需要一個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); }); 
+0

得到它!非常感謝你 – stackOverFlew

+1

= o正試圖爲你構建一個jsFiddle例子,但既然你知道了......那麼我會放棄這個想法:P懶得建立一個hee –

+0

哈哈謝謝!我剛剛發佈了我最終使用的代碼。非常感謝! – stackOverFlew