javascript google maps API - 更改标记的标题

时间:2016-08-18 01:28:48

标签: javascript google-maps google-maps-api-3

我正在尝试在Google地图标记图标上填充小注释。标题似乎没有这样做。我阅读了文档,但找不到任何内容。

enter image description here 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"


                  });

现在,即使设置了注释的标题,注释也是空白的。我从来没有弄清楚标题实际上是用于什么,因为标签是针对图标内的字符而标题对注释没有影响。

您可以使用文本填充注释的标记的属性是什么?

修改 谢谢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 个答案:

答案 0 :(得分: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); });