我将需要在同一页面上至少有 3 张地图(一张在另一张下方,而不是并排),每张地图都包含多个标记。谁能告诉我如何在同一页面上获得三个版本(之后我可以修改每个版本的详细信息)?我基本上在这里感觉自己的方式,对javascript知之甚少。
非常感谢 - 罗杰
<div id="map" style="height:400px;width:541px;display:block;">
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
function mapIt(){
var latlng = new google.maps.LatLng(24.00, 0.00);
var myOptions = {
zoom: 1,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
}
var map = new google.maps.Map(document.getElementById('map'), myOptions);
setMarkers(map, places);
}
var places = [
['London',51.50, -0.125,"Markers/green.png"],
['Abidjan',5.34, -4.03,"Markers/red2.png"],
['Abu Dhabi',24.47, 54.37,"Markers/red2.png"],
];
var popUps = [
'<strong>London</strong><br />link to larger map',
'<strong>Abidjan, Ivory Coast</strong><br />Content here',
'<strong>Abu Dhabi, United Arab Emirates</strong><br />Content here>',
]
var infowindow;
function setMarkers(map, locations) {
for (var i = 0; i < places.length; i++) {
var myLatLng = new google.maps.LatLng(locations[i][1], locations[i][2]);
var icon = locations[i][3];
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: locations[i][0],
icon: icon
});
(function(i, marker) {
google.maps.event.addListener(marker,'click',function() {
if (!infowindow) {
infowindow = new google.maps.InfoWindow();
}
infowindow.setContent(popUps[i]);
infowindow.open(map, marker);
});
})(i, marker);
}
};
mapIt();
</script></div>