Javascript 如何在google maps API标记上添加自定义标题?
我正试图为一个标记添加一个标题,就像maps.google为他们的标记添加一个标题一样,如下所述,“约塞米蒂瀑布旅馆” 我一直在搜索MapsAPI以获取有关如何操作的信息,我尝试将“标签”和“标题”添加到新的标记对象中,但这些都不起作用。maps API上没有关于如何实现这一点的任何其他信息Javascript 如何在google maps API标记上添加自定义标题?,javascript,api,google-maps,labels,markers,Javascript,Api,Google Maps,Labels,Markers,我正试图为一个标记添加一个标题,就像maps.google为他们的标记添加一个标题一样,如下所述,“约塞米蒂瀑布旅馆” 我一直在搜索MapsAPI以获取有关如何操作的信息,我尝试将“标签”和“标题”添加到新的标记对象中,但这些都不起作用。maps API上没有关于如何实现这一点的任何其他信息 var marker = new google.maps.Marker({ position: {lat: beach[1], lng: beach[2]}, map: map,
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”所提到的,谷歌没有分享在标记上添加标签的技术。你必须加上你自己的。 这里的“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);
};
var图像={
url:“./customMarker.jpg”,
//此标记宽20像素,高32像素。
大小:新谷歌地图大小(100100),
//此图像的原点是(0,0)。
来源:新google.maps.Point(0,0),
//此图像的锚定位于(0,32)处旗杆的底部。
主播:新google.maps.Point(0,32)
};
新标签=[
[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],
];
对于(var i=0;i
正如“Geocodezip”所提到的,谷歌没有共享在标记上添加标签的技术。你必须加上你自己的。
这里的“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);
};
var图像={
url:“./customMarker.jpg”,
//此标记宽20像素,高32像素。
大小:新谷歌地图大小(100100),
//此图像的原点是(0,0)。
来源:新google.maps.Point(0,0),
//此图像的锚定位于(0,32)处旗杆的底部。
主播:新google.maps.Point(0,32)
};
新标签=[
[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],
];
对于(var i=0;i
本机API不支持它。可能是您与第三方库最接近的位置,您可以设置“label”div的样式。或者您可能不确定这是否有帮助,但您可以向Google注册位置,它最终将显示在地图中。尝试使用label
,title
用于滚动文本,并且没有基于资源的text
属性<代码>文本是MarkerLabel资源的一部分,本机API不支持它。可能是您与第三方库最接近的位置,您可以设置“label”div的样式。或者您可能不确定这是否有帮助,但您可以向Google注册位置,它最终将显示在地图中。尝试使用label
,title
用于滚动文本,并且没有基于资源的text
属性<代码>文本是MarkerLabel资源的一部分