我正在使用Google Maps API v3。我有一個地圖佔用整個頁面上的自定義標記。我希望每個標記點擊時打開一個信息窗口,其中包含指向與該位置有關的網頁的鏈接。但是,即使我另有指定,所有標記都會在信息窗口中顯示相同的內容。這是我的代碼,你可以試着修復它嗎?所有信息窗口顯示我最後指定的聲明的內容。我只是在這裏粘貼了所有的代碼,因爲我可能在任何地方犯了一個錯誤。謝謝...在Google Maps API中,如何在多個信息窗口中插入多個標記?
<!doctype html>
<head>
<title>L4H Expansion</title>
<style type="text/css">
html, body {
height: 100%;
margin: 0;
padding: 0;
}
a {
color: #8c4e94;
text-decoration: none;
}
p {
line-height: 1.8;
margin-bottom: 15px;
font-family: 'georgia', serif;
font-size: 14px;
font-weight: normal;
color: #6d6d6d;
}
#map_canvas {
height: 100%;
}
#header {
background: url('http://static.tumblr.com/asviked/Cqklq72up/header.png') top center repeat-x;
height: 105px;
border-bottom: 1px solid #e0e0dc;
-webkit-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.6);
-moz-box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.6);
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.6);
position: fixed;
top: 0px;
left: 0px;
right: 0px;
z-index: 99;
}
#headercon {
width: 900px;
margin: 0 auto;
}
#headerwrap {
background: url('http://static.tumblr.com/asviked/dzAlqx6kq/title.png') top left no-repeat;
width: 900px;
overflow: hidden;
height: 100px;
}
</style>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {
var Manassas = new google.maps.LatLng(38.751272,-77.475243);
var London = new google.maps.LatLng(51.611544,-0.178072);
var Richmond = new google.maps.LatLng(37.543216,-77.468376);
var Harrisonburg = new google.maps.LatLng(38.451841,-78.868961);
var myOptions = {
zoom: 4,
center: Manassas,
mapTypeId: google.maps.MapTypeId.TERRAIN,
disableDefaultUI: true
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var marker = new google.maps.Marker({
position: Manassas,
map: map,
title:"Linux4Hope Manassas VA",
icon: 'http://static.tumblr.com/asviked/U1flr229o/marker.png'
});
var infowindow = new google.maps.InfoWindow({
position: Manassas,
content: '<p><a href="http://www.linux4hope.org">Linux4Hope, Manassas VA, USA</a></p>'
});
google.maps.event.addListener(marker, 'click', function() {
position: Manassas,
infowindow.open(map, this);
});
var marker = new google.maps.Marker({
position: London,
map: map,
title:"Linux4Hope UK",
icon: 'http://static.tumblr.com/asviked/U1flr229o/marker.png'
});
var infowindow = new google.maps.InfoWindow({
position: London,
content: '<p><a href="http://www.linux4hope.org.uk">Linux4Hope, London, United Kingdom</a></p>'
});
google.maps.event.addListener(marker, 'click', function() {
position: London,
infowindow.open(map, this);
});
var marker = new google.maps.Marker({
position: Richmond,
map: map,
title:"Linux4Hope Richmond VA",
icon: 'http://static.tumblr.com/asviked/U1flr229o/marker.png'
});
var infowindow = new google.maps.InfoWindow({
position: Richmond,
content: '<p><a href="http://www.linux4hope.org">Linux4Hope, Richmond VA, USA</a></p>'
});
google.maps.event.addListener(marker, 'click', function() {
position: Richmond,
infowindow.open(map, this);
});
var marker = new google.maps.Marker({
position: Harrisonburg,
map: map,
title:"Linux4Hope Harrisonburg VA",
icon: 'http://static.tumblr.com/asviked/U1flr229o/marker.png'
});
var infowindow = new google.maps.InfoWindow({
position: Harrisonburg,
content: '<p><a href="http://www.linux4hope.org">Linux4Hope, Harrisonburg VA, USA</a></p>',
});
google.maps.event.addListener(marker, 'click', function() {
position: Harrisonburg,
infowindow.open(map, this);
});
}
</script>
</script>
</head>
<body onload="initialize()">
<div id="header">
<div id="headercon">
<a href="http://www.linux4hope.org">
<div id="headerwrap">
</div>
</a>
</div>
</div>
<div id="map_canvas"></div>
</body>
</html>
我也許應該指出,這是我第一次使用JavaScript,所以我不知道任何與JS相關的術語。但是,我得到的答案是有幫助的。 :) – mkras