所以目前我有3个不同的地图标记:标记1 =显示用户的当前位置,标记2 =商店A的位置,标记3 =商店B的位置
[我想做的是,当用户单击标记2和3时,它们将被自动带到下一页,而当他们单击标记1时,则什么也没有发生(意味着它们不会被带到下一页) 。
[当前,当我单击标记1、2和3时,会将用户带到下一页,但是我不希望在单击标记1时将用户带到下一页。有没有办法删除标记1的google.maps.event.addListener
?
//Code for Marker 1
function findMe() {
$('#popupDialogue').popup();
$('#popupDialogue').popup('open');
navigator.geolocation.getCurrentPosition(onFindSuccess, onError);
};
function onFindSuccess(position) {
$('#popupDialogue').popup('close');
var latlong = new google.maps.LatLng(position.coords.latitude,
position.coords.longitude);
var mapProp = {
center: latlong,
zoom: 18,
mapTypeId: google.maps.MapTypeId.HYBRID
};
var map = new google.maps.Map(document.getElementById("map-canvas"), mapProp);
var content = "<h3>You are here</h3>";
var title = "Your position";
addMarkersToMap(map, latlong, title, content);
google.maps.event.removeListener(marker);
}
function onError(error) {
alert("Encounter an error")
}
//Code for adding map markers to the map
function addMarkersToMap(map, latlong, title, popcontent) {
var marker = new google.maps.Marker({
position: latlong,
map: map,
title: title
});
var infowindow = new google.maps.InfoWindow({
content: popcontent
});
infowindow.open(map, marker);
google.maps.event.addListener(marker, 'click', function () {
$(":mobile-pagecontainer").pagecontainer("change", "#page3", {
role: "page"
});
});
}
//Code for map markers 2 and 3
function showPoints() {
var latlong = new google.maps.LatLng(1.311166, 103.775583);
var mapProp = {
center: latlong,
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"), mapProp);
$.each(points, function (index, val) {
var latlong2 = new google.maps.LatLng(val.latitude, val.longitude);
addMarkersToMap(map, latlong2, val.title, val.content);
});
}
//Code for displaying map on the page
$(document).on("pagecreate", "#page2", function () {
var map = new google.maps.Map(document.getElementById('map-canvas'), {
center: {
lat: 11.3083,
lng: 103.7776
},
zoom: 14,
mapTypeId: 'roadmap'
});
});
您可以将标记分开,例如var marker2-3 = new google.maps.Marker({位置:拉特隆,地图:标题:标题});var marker1 = new google.maps.Marker({位置:拉特隆,地图:标题:标题});
感谢您的所有帮助,这是我所拥有的解决方案,它可以正常工作!我之所以能够派生此解决方案,是因为注释告诉我将事件应用于标记2和3而不是标记1。我使用了这个概念,并创建了另一个仅添加标记1的函数,并删除了此函数的侦听器,因此得出了解决方案。