0
var lats = ["56.1581702","56.1580875","56.1588094","56.1510389","56.15943499999999","56.1576479"];
var lons = ["13.767593300000044","13.752623399999948","13.764544","13.768728699999997","13.768018600000005","13.76731380000001"];
var i = 0;
var image = '/bilder/location.png';
for(lats.length > i) {
      var marker = new google.maps.Marker({
            map: map,
            position: new google.maps.LatLng(lats[i], lons[i]),
            icon: image
        });
 var i++;
}

无法使此代码正常工作,仅显示空白地图。

4

1 回答 1

1

您的for循环表达式无效。尝试这个 :

var lats = ["56.1581702","56.1580875","56.1588094","56.1510389","56.15943499999999","56.1576479"];
var lons = ["13.767593300000044","13.752623399999948","13.764544","13.768728699999997","13.768018600000005","13.76731380000001"];
var image = '/bilder/location.png';
for(var i = 0; i < lats.length; ++i) {
  var marker = new google.maps.Marker({
        map: map,
        position: new google.maps.LatLng(lats[i], lons[i]),
        icon: image
    });
}

现代浏览器中可用的开发人员工具将帮助您调试代码中的语法错误。

于 2013-01-08T00:49:33.977 回答