我的目标是创建一个包含多个位置的地图,当地图上的其他位置点击html标记时,地图会从标记跳转到标记
我做了跳跃工作但是,我似乎无法让鼠标悬停信息框工作...我有搜索但找不到这个具体问题
www.humphrey-ray.com/qp/locations-new27a.html
答案 0 :(得分:3)
工作示例..
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3.4key=AIzaSyCjceQVdlfYNqKfDcrAl50VIXrzBXMhDbo&sensor=false">
</script> <script type="text/javascript">
var map;
var marker2;
var marker3;
var marker4;
var marker5;
var infowindow = new google.maps.InfoWindow();
function initialize() {
var latlng = new google.maps.LatLng(39.94718, -75.14323);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
marker2 = new google.maps.Marker({
position: new google.maps.LatLng(39.94718, -75.14323),
map: map,
title: "my 2nd title"
});
new google.maps.event.addListener( marker2, 'mouseover', function() {
infowindow.setContent("my 2nd title");
infowindow.open(map,this);
});
marker3 = new google.maps.Marker({
position: new google.maps.LatLng(39.94924, -75.14268),
map: map,
title: "my 2nd title"
});
new google.maps.event.addListener( marker3, 'mouseover', function() {
infowindow.setContent("my 3nd title");
infowindow.open(map,this);
});
marker4 = new google.maps.Marker({
position: new google.maps.LatLng(39.96146, -75.14325),
map: map,
title: "my 2nd title"
});
new google.maps.event.addListener( marker4, 'mouseover', function() {
infowindow.setContent("my 4nd title");
infowindow.open(map,this);
});
marker5 = new google.maps.Marker({
position: new google.maps.LatLng(39.95098, -75.14558),
map: map,
title: "my 5nd title"
});
new google.maps.event.addListener( marker5, 'mouseover', function() {
infowindow.setContent("my 5nd title");
infowindow.open(map,this);
});
}
function goToLoc(id){
if(id== 2)
map.setCenter(marker2.getPosition());
if(id == 3)
map.setCenter(marker3.getPosition());
if(id == 4)
map.setCenter(marker4.getPosition());
if(id == 5)
map.setCenter(marker5.getPosition());
}
</script> <style type="text/css">
body,td,th { font-family: Arial, Helvetica, sans-serif; }
</style>
</head>
<body onload="initialize()">
<div id="container">
<!-- /header -->
<!-- /nav -->
<div class="mapwrapper">
<div class="mapwrapper" id="map_canvas" style="width:720px; height:400px">
</div>
<div class="mapwrapper">
<div class="right-top-column">
<div class="right-top-column-inner">
<br>
<img src="img/comin_soon.jpg" width="180" height="186" />
</p>
</div>
</div>
<div class="right-top-column-noshaw">
<h1>
Click Location to show on map
</h1>
<ul class="side-list">
<li>
<a href="#" id="marker2" onclick="goToLoc(2)">
Old City</a>
</li>
<li>
<a href="#" id="marker3" onclick="goToLoc(3)">
South Street/Society Hill</a>
</li>
<li>
<a href="#" id="marker4" onclick="goToLoc(4)">
Northern Liberties</a>
</li>
<li>
<a href="#" id="marker5" onclick="goToLoc(5)">
Old City</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</body>
</html>