标题说明
我有一个带有几个标记的谷歌地图,每个标记都有一个信息窗口。
操作:
触发标记和侦听器中的用户点击 - 确定 用户点击onclick函数[myclick(i)]显示信息窗口(特定标记)
错误:
myclick(i)第一次工作,之后不会!
代码:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="js/jquery.scrollTo.js"></script>
<script type="text/javascript">
var markers = [];
var locations = [
['PLace 1', -8.2306155581, 37.0871796116, 'A', 'info 1'],
['Place 2', -8.5448366404, 37.1314707841, 'B', 'info 2']];
function showmap() {
$('#results_map').toggle();
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(37.083, -8.25),
mapTypeId: google.maps.MapTypeId.SATELLITE
});
var i;
google.maps.event.trigger(map, 'resize');
for (i = 0; i < locations.length; i++) {
markers[i] = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][2], locations[i][1]),
map: map,
icon: 'http://chart.apis.google.com/chart?chst=d_map_pin_letter&chld='+locations[i][3]+'|FF0000|FFFFFF',
title: locations[i][0]
});
markers[i].info = new google.maps.InfoWindow({
content: locations[i][4]
});
markers[i].setMap(map);
}
google.maps.event.addListener(markers[0], 'click', function(){
$(document.body).scrollTo('#placeA', 800, 'swing');
markers[0].info.close();
});
google.maps.event.addListener(markers[1], 'click', function(){
$(document.body).scrollTo('#placeB', 800, 'swing');
markers[1].info.close();
});
}
function myclick(i) {
$(document.body).scrollTo('#results', 800, 'swing');
markers[i].info.open(map, markers[i]);
}
</script>
<div id="results_map"><div id="map"></div></div>
<a href="javascript:;" onclick="myclick(0)">Map 1</a>
<a href="javascript:;" onclick="myclick(1)">Map 2</a>
我的错误在哪里?
感谢您的帮助
园艺