gpt4 book ai didi

javascript - 如何在谷歌地图 API 标记上添加自定义标题?

转载 作者:行者123 更新时间:2023-11-28 06:30:12 26 4
gpt4 key购买 nike

我正在尝试向标记添加标题,就像maps.google向其标记添加标题一样,如下所述,“Yosemite Lodge at the Falls”

maps.google.com marker labeling

我一直在 map API 中搜索有关如何执行此操作的信息,我尝试将“标签”和“标题”添加到新的标记对象,但这些都不起作用。 map 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',
});

最佳答案

正如“Geocodezip”提到的,Google 不共享在其标记上添加标签的技术。您必须添加自己的。 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);
};

关于javascript - 如何在谷歌地图 API 标记上添加自定义标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34775405/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com