【发布时间】:2011-08-12 15:35:09
【问题描述】:
谁能帮忙。我有以下代码,但是当我单击标记时,它会将我重定向到同一页面:
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script type="text/javascript">
function initialize() {
var myOptions = {
zoom: 14,
center: new google.maps.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>),
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: true,
scrollwheel: false
}
var map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
for (var i = 0; i < locations.length; i++) {
var image = new google.maps.MarkerImage('images/greenmarkers/'+ i +'.png');
var location = locations[i];
var myLatLng = new google.maps.LatLng(location[1], location[2]);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
icon: image,
title: location[0],
url: location[3]
});
google.maps.event.addListener(marker, 'click', function() {
window.location.href = marker.url;
});
}
}
</script>
<script type="text/javascript">
var locations = [['test', 63.3740200000000, 19.6301320000000, 'http://www.test.com'],['test1', 63.3725155758185, 19.6264879703522, 'http://www.test1.com'],['test2', 63.3762550022764, 19.6305649280548, 'http://www.test2.com']];
</script>
【问题讨论】:
-
看起来像 common function-in-a-loop issue。有关修复它的基本方法,请参阅stackoverflow.com/questions/6939983/…。
-
谢谢马特。我试过了,但没有运气。