我想在这里做什么.当我按下标记时.它应该将我发送到该ID的页面.它发送我到ID的页面.但是,我单击哪个标记并始终访问相同ID的页面并不重要.侦听器无法正常运行…我想…
这是完整的地图:
var estates = <?PHP echo json_encode($estates);?>;
function initMap()
{
var options =
{
zoom : 6,
center : {lat:34.652500, lng:135.506302}
};
var map = new google.maps.Map(document.getElementById('map'), options);
@foreach ($estates as $est)
var marker = new google.maps.Marker({
map: map,
icon: 'imgs/marker.png',
url: "/pages/{{$est->id}}",
label: {
text: estates.data[0].price.substring(0, 5),
color: "#fff",
},
position: {
lat: {{$est->lat}},
lng: {{$est->lng}}
}
});
google.maps.event.addListener(marker, 'click', function () {
window.location.href = marker.url;
});
@endforeach
}
有解决这个问题的主意吗?
解决方法:
请试试:
google.maps.event.addListener(marker, 'click', function () {
window.location.href = this.url;
});