【问题标题】:javascript google maps API - change title of markerjavascript google maps API - 更改标记的标题
【发布时间】:2016-12-24 19:38:34
【问题描述】:

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

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

【问题讨论】:

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


    【解决方案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); });
    

    【讨论】:

    • =o 试图为你构建一个 jsFiddle 示例,但既然你得到了它......那我就放弃这个想法:P 懒得构建一个 hee
    • 哈哈谢谢!我刚刚发布了我最终使用的代码。非常感谢!
    猜你喜欢
    • 2022-11-26
    • 2011-10-30
    • 1970-01-01
    • 2013-05-31
    • 2011-12-11
    • 1970-01-01
    • 2013-08-31
    • 2011-09-13
    • 1970-01-01
    相关资源
    最近更新 更多