2013-01-08 77 views
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++; 
} 

無法讓此代碼工作,只顯示空白地圖。無法添加標記從陣列通過for循環

回答

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 
    }); 
} 

現代瀏覽器中可用的開發人員工具將幫助您調試代碼中的語法錯誤。

+0

謝謝,這解決了問題! :) – ericwenn