google 地图 - 从数组中选取值并分配给标记
google maps - pick value from array and assign to marker
过去 2 小时我一直在尝试找出要做什么,但似乎找不到答案。我想要做的是我有 5 个不同的标记,最后编号为 1、2、3、4、5,并且也分为 2 类(1 和 2)。我还有一个 Info-window,当我单击特定标记 3 时,我希望打开 info-window。在 infowindow 代码中我有标记:,.我可以在 link 中向特定标记添加什么?非常感谢大家
P.s。当我放置 marker: newevent; 时,它只显示 infowindow。由于某种原因,第五个标记将显示信息 window。
var beaches = [
['Bondi Beach', -33.890542, 151.274856, 1,1],
['Coogee Beach', -33.923036, 151.259052, 1,2],
['Cronulla Beach', -34.028249, 151.157507, 2,3],
['Manly Beach', -33.800101, 151.287478, 2,4],
['Maroubra Beach', -33.950198, 151.259302, 2,5] ];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(-33.88, 151.28),
styles: mapStyle });
newevent.category = beaches[i][3];
markers.push(newevent);
}
function displayMarkers(category) {
var i;
for (i = 0; i < markers.length; i++) {
if (markers[i].category === category) {
markers[i].setVisible(true);
}
else {
markers[i].setVisible(false);
}
}
}
和信息window:
var info = new SnazzyInfoWindow({
marker: ,
placement: 'right',
offset: {
left: '20px'
},
等..
谢谢!
我会给你一个我认为你可以用来解决你的问题的想法。当你创建你的标记时,给它们一个唯一的 ID 怎么样......例如,如果你有一个创建标记的函数:
var uniqueId = 1;
//more code
function addMarker(location) {
var marker = new google.maps.Marker({
position: location,
map: map
});
marker.id = uniqueId;
uniqueId++;
}
所以现在你可以link任何你想对任何特定标记做的事情,例如,如果你想删除一个特定标记并且你有删除标记的功能:
function deleteMarker(id) {
for (var i = 0; i < markers.length; i++) {
if (markers[i].id == id) {
markers[i].setMap(null);
markers.splice(i, 1);
return;
}
}
};
您可以将 Id 作为参数传递...或使用 if,例如:
if (uniqueId == 3 ) {
//Do whatever I want
}
过去 2 小时我一直在尝试找出要做什么,但似乎找不到答案。我想要做的是我有 5 个不同的标记,最后编号为 1、2、3、4、5,并且也分为 2 类(1 和 2)。我还有一个 Info-window,当我单击特定标记 3 时,我希望打开 info-window。在 infowindow 代码中我有标记:,.我可以在 link 中向特定标记添加什么?非常感谢大家
P.s。当我放置 marker: newevent; 时,它只显示 infowindow。由于某种原因,第五个标记将显示信息 window。
var beaches = [
['Bondi Beach', -33.890542, 151.274856, 1,1],
['Coogee Beach', -33.923036, 151.259052, 1,2],
['Cronulla Beach', -34.028249, 151.157507, 2,3],
['Manly Beach', -33.800101, 151.287478, 2,4],
['Maroubra Beach', -33.950198, 151.259302, 2,5] ];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(-33.88, 151.28),
styles: mapStyle });
newevent.category = beaches[i][3];
markers.push(newevent);
}
function displayMarkers(category) {
var i;
for (i = 0; i < markers.length; i++) {
if (markers[i].category === category) {
markers[i].setVisible(true);
}
else {
markers[i].setVisible(false);
}
}
}
和信息window:
var info = new SnazzyInfoWindow({
marker: ,
placement: 'right',
offset: {
left: '20px'
},
等..
谢谢!
我会给你一个我认为你可以用来解决你的问题的想法。当你创建你的标记时,给它们一个唯一的 ID 怎么样......例如,如果你有一个创建标记的函数:
var uniqueId = 1;
//more code
function addMarker(location) {
var marker = new google.maps.Marker({
position: location,
map: map
});
marker.id = uniqueId;
uniqueId++;
}
所以现在你可以link任何你想对任何特定标记做的事情,例如,如果你想删除一个特定标记并且你有删除标记的功能:
function deleteMarker(id) {
for (var i = 0; i < markers.length; i++) {
if (markers[i].id == id) {
markers[i].setMap(null);
markers.splice(i, 1);
return;
}
}
};
您可以将 Id 作为参数传递...或使用 if,例如:
if (uniqueId == 3 ) {
//Do whatever I want
}