JS小提琴:http: //jsfiddle.net/megatimes/NVDLf/7/
我有一个从数组创建多个标记的地图.在地图下方是一些链接,当点击时,我想使地图平移到其各自的标记,并打开信息窗口.
鉴于我不想生成链接本身作为创建标记的循环的一部分,我该怎么做?
我很确定这是一个范围问题,因为地图下面的链接都打开了位置数组中的最后一项,但我似乎无法弄清楚如何绕过它.
谢谢
var locations = [
[
"Location 1",
"215 West Girard Avenue 19123",
"39.9695601",
"-75.1395161"
],
[
"Location 2",
"5360 Old York Road 19141",
"40.034038",
"-75.145223"
],
[
"Location 3",
"1350 W Girard Avenue 19123",
"39.9713524",
"-75.1590360"
]
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 12,
center: new google.maps.LatLng(39.9995601, -75.1395161),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = …Run Code Online (Sandbox Code Playgroud)