如何在 google 地图 API 标记上添加自定义标题?
how to add custom title on a google maps API marker?
我正在尝试为标记添加标题,方法与 maps.google 向其标记添加标题的方式相同,如下所述,"Yosemite Lodge at the Falls"
我一直在地图 API 中搜索有关如何操作的信息,我尝试将 'labels' 和 'title' 添加到新标记 object 但 none 这些工作。地图 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' 例子解决了我的问题。它允许您添加标记
我稍微编辑了代码,以便能够添加多个 marker/label 对
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);
};
我正在尝试为标记添加标题,方法与 maps.google 向其标记添加标题的方式相同,如下所述,"Yosemite Lodge at the Falls"
我一直在地图 API 中搜索有关如何操作的信息,我尝试将 'labels' 和 'title' 添加到新标记 object 但 none 这些工作。地图 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' 例子解决了我的问题。它允许您添加标记 我稍微编辑了代码,以便能够添加多个 marker/label 对
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);
};