gpt4 book ai didi

javascript - Google map 标记 - 为每个标记添加一个带有唯一标签的自定义图标

转载 作者:行者123 更新时间:2023-11-30 18:01:12 25 4
gpt4 key购买 nike

我已经实现了一个带有多个标记的谷歌地图,但我没有做的是如何为每个标记添加一个唯一的标签,即每个标记需要有一个字母:
例如
标记 1 需要显示 'A'
标记 2 需要显示 'B'
标记 3 需要显示 'C'
标记 4 需要显示 'D'
...
我想要实现的一个例子是:http://www.athenos.com/locator/ --- 在 zip 搜索中输入 11205

这是我的 map 代码的一部分 - 我的 initadd_marker 方法:

init : function() {

var self = this;

// set map property
var map = new google.maps.Map(self.dom_element, self.options);
self.map = map;

// set some other shit
new google.maps.Size(95, 77),
new google.maps.Point(0,0),
new google.maps.Point(47, 76);

// creating new bounds
var bounds = new google.maps.LatLngBounds();

// for loop to iterate through locations
for (var i = 0; i < self.locations.length; i++) {

// extend the bounds
bounds.extend(self.locations[i].latlng);

// add the marker
self.add_marker(self.locations[i].latlng, i);
}

// centers the map based on the existing map markers
self.map.fitBounds(bounds);
},

add_marker : function(latlng, marker_index) {
var self = this;
var marker = new google.maps.Marker({
position: latlng,
map: self.map,
icon: self.map_icon,
zIndex: 998,
id: marker_index // give the marker an ID e.g. 0, 1, 2, 3 - use this for indexing the listed venues
});

google.maps.event.addListener(marker, 'mouseover', function(event) {

var this_marker = this;
// executes handler and passes the marker as 'this' and event data as an argument
self.handle_marker_mouseover.call(self, this, event);
this_marker.setZIndex(999);

});

google.maps.event.addListener(marker, 'mouseout', function(event) {

// executes handler and passes the marker as 'this' and event data as an argument
self.handle_marker_mouseout.call(self, this, event);


});

google.maps.event.addListener(marker, 'click', function(event) {

// executes handler and passes the marker as 'this' and event data as an argument
self.handle_marker_click.call(self, this, event);


});
},

...

请帮忙。提前致谢

最佳答案

只需尝试在标记的 Prop 中在此 url 中找到您的图标: http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld=7|00FF00|000000

所以用字母遍历 chld 查询字符串参数的第一部分,不要忘记选择标记的颜色(最新的两部分,竖线分隔)

关于javascript - Google map 标记 - 为每个标记添加一个带有唯一标签的自定义图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16959432/

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