2016-01-13 179 views
1

我想添加标题标记,在的maps.google以同样的方式增加了一个标题,以他们的标志,如下所述,“优胜美地Lodge酒店的瀑布”如何在Google Maps API标记上添加自定义标题?

maps.google.com marker labeling

我我一直在搜索地图API以了解如何做到这一点,我尝试在新的Marker对象中添加“标签”和“标题”,但没有任何工作。没有在地图API的任何其他信息就如何做到这一点

var marker = new google.maps.Marker({ 
     position: {lat: beach[1], lng: beach[2]}, 
     map: map, 
     icon: image, 
     shape: shape, 
     draggable: true, 
     animation: google.maps.Animation.DROP, 
     title: beach[0], 
     zIndex: beach[3], 
     text: 'australia', 
}); 
+0

它不受本地API支持。 [MarkerWithLabel](http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerwithlabel/docs/examples.html)可能是最接近第三方的图书馆,您可以调整风格“标签”分区。或者您可以尝试[MapLabel](https://github.com/googlemaps/js-map-label) – geocodezip

+0

不确定这是否有帮助,但您可以使用Google注册位置,并最终会在地图上本地显示。 – GreatBlakes

+0

尝试使用'label','title'用于翻页文本,并且没有基于[Marker]的文本属性(https://developers.google.com/maps/documentation/javascript/3.exp/reference#Marker)资源。 'text'是MarkerLabel资源的一部分 – adjuremods

回答

0

如前所述“Geocodezip”,谷歌不共享技术在他们的标记添加标签。你必须添加你自己的。 markerwithlabel'basic.html'示例在这里解决了我的问题。它允许你添加标记 我编辑了一下代码以便能够添加多个标记/标记对

var image = { 
    url: './customMarker.jpg', 
    // This marker is 20 pixels wide by 32 pixels high. 
    size: new google.maps.Size(100, 100), 
    // The origin for this image is (0, 0). 
    origin: new google.maps.Point(0, 0), 
    // The anchor for this image is the base of the flagpole at (0, 32). 
    anchor: new google.maps.Point(0, 32) 
    }; 

var NewLabels=[ 

['Test2', 34.03, -118.235], 
['Test1', 35.03, -117.235], 
['Test2', 36.03, -116.235], 
['Test3', 37.03, -115.235], 
['Test4', 38.03, -114.235], 

]; 

    for (var i = 0; i < NewLabels.length; i++) { 
     var title = NewLabels[i][0]; 
     var title = new MapLabel({ 
      text: NewLabels[i][0], 
      position: new google.maps.LatLng(NewLabels[i][1], NewLabels[i][2]), 
      map: map, 
      fontSize: 20, 
      align: 'right' 
     }); 

     var marker = new google.maps.Marker({animation: google.maps.Animation.DROP, icon: image,}); 
     marker.bindTo('map', title); 
     marker.bindTo('position', title); 
     marker.setDraggable(true); 
}; 
相关问题