我坚持这个问题,无论我尝试过什么,我都无法在谷歌地图标记中添加网址。
任何比我更有经验的人都可以帮助解决这个问题。
目前,如果我点击标记,我将回到主页,我想要的是转到foreach循环中的此网址'/Hotel/Full-Details?=@item.DisplayHotelName&propId=@item.HotelId'
。
我看了
google map api: open url by clicking at marker
和其他但我被困了
我的代码是:
<script type="text/javascript">
$(function() {
var map;
var markersArray = [];
var image = 'img/';
var bounds = new window.google.maps.LatLngBounds();
var loc;
//var pageUrl;
var mapOptions = { mapTypeId: window.google.maps.MapTypeId.ROADMAP };
map = new window.google.maps.Map(document.getElementById("dvMap"), mapOptions);
@foreach (var item in Model.DisplayHotelPaging)
{
<text> loc = new google.maps.LatLng(@item.Latitude, @item.Longitude);
bounds.extend(loc);
addMarker(loc, '@item.DisplayHotelName @item.Address1 @item.PostalCode', "active",'/Hotel/Full-Details?=@item.DisplayHotelName&propId=@item.HotelId')
</text>
}
map.fitBounds(bounds);
map.panToBounds(bounds);
//for (var i = 0; i < window.addMarker.length; i++) {
function addMarker(location, name, active) {
//var page = loc[i];
var marker = new google.maps.Marker({
position: location,
map: map,
title: name,
status: active,
icon: '/Images/property1.png',
url: '/'//page[3]
});
// }
window.google.maps.event.addListener(marker, 'click', function() {
window.location.href = marker.url;
});
}
});
</script>
感谢您的帮助
答案 0 :(得分:1)
我认为您需要将URL添加到addMarker函数中,如下所示:
function addMarker(location, name, active, markerUrl) {
//var page = loc[i];
var marker = new google.maps.Marker({
position: location,
map: map,
title: name,
status: active,
icon: '/Images/property1.png',
url: markerUrl
});
// }
window.google.maps.event.addListener(marker, 'click', function() {
window.location.href = marker.url;
});
}
目前你用硬编码&#39; /&#39;作为将您带到主页的URL。