简体   繁体   English

JavaScript Google Maps API-更改标记的标题

[英]javascript google maps API - change title of marker

I am trying to populate the small annotation on a google map marker icon. 我正在尝试在Google地图标记图标上填充小的注释。 Title doesn't seem to do it. 标题似乎没有做到。 I read the documentation, but can't find anything. 我阅读了文档,但找不到任何东西。

在此处输入图片说明 https://developers.google.com/maps/documentation/javascript/examples/marker-labels 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"


                  });

Right now the annotations are blank, even though the title for the annotations is set. 现在,即使已设置注释的标题,注释仍为空白。 I never figured out what the title is actually used for either, since label is for the character inside the icon and the title has no effect on the annotation. 我从来没有弄清楚标题的实际用途,因为标签是图标中字符的标题,标题对注释没有影响。

What is the property of the marker with which you can populate the annotation with text? 您可以使用标记填充文本标记的属性是什么?

EDIT: Thanks Samuel Toh. 编辑:谢谢塞缪尔·托。

Here is the the working code I ended up using: 这是我最终使用的工作代码:

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

You need an infoWindow object to display the title text. 您需要一个infoWindow对象来显示标题文本。

See: https://developers.google.com/maps/documentation/javascript/examples/infowindow-simple 请参阅: 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM