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

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

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

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"


                  });

现在,即使注释的标题已设置,注释仍为空白。我从来没有弄清楚标题的实际用途,因为标签是图标内的字符,标题对注释没有影响。

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

编辑: 谢谢塞缪尔·杜。

这是我最终使用的工作代码:

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

最佳答案

您需要一个 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); });

关于javascript google map API - 更改标记的标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39008609/

相关文章:

javascript - 方法是javascript中属性的子集吗?

android - 如何实现像 uber android 一样的可拖动 map ,使用更改位置进行更新

android - 数据可用后将标记添加到 Google map ?

javascript - Google Maps API-infoWindow填充屏幕中的嵌入式YouTube

google-maps - 矩形完成后如何暂时停止绘制

google-maps - Google Elevation API - 限制

在设置 CDO.Message 选项时使用的 f(x) = y JScript 习惯用法的 JavaScript 友好替代方案

javascript - 导入 app.use() 中 require 的等效项

javascript - 我可以只删除 Google Maps API v3 中 POI 的弹出气泡吗?

javascript - this.state 在 React 组件中引用了什么?