2016-08-18 63 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