2011-05-27 87 views
0

我有一個繪製標記的簡單代碼,然後用折線將它們連接在一起,但我嘗試使用Polyline的MVCArray不起作用(以及「不工作「我的意思是折線沒有被繪製)。這裏是我的代碼:Google Maps API MVCArray未被Polyline接受()

$(document).ready(function(){ 
    var latlng = new google.maps.LatLng(36.686041,-80.661621); 
    var map = new google.maps.Map(document.getElementById("network_map"),{ 
     zoom: 6, 
     center: latlng, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }); 

    $("input[name='submit']").click(function() { 
     var geocoder = new google.maps.Geocoder(); 
     var locations = new google.maps.MVCArray(); 
     var i = 0; 
     $("input[name='address[]']").each(function() { 
      geocoder.geocode({"address" : this.value }, function(results) { 
       var addrLl = results[0].geometry.location; 
       locations.insertAt(locations.length, addrLl); 
       var marker = new google.maps.Marker({ 
        map: map, 
        position: addrLl 
       }); 
      }); 
     }); 
     console.log(locations); 
     var connectPath = new google.maps.Polyline({ 
      path: locations, 
      strokeColor: "#FF0000", 
      strokeOpacity: 1.0, 
      strokeWeight: 100, 
      map: map 
     }); 
     return false; 
    }); 
}); 

// console.log(locations); result from firebug 
W { b=[0], gm_accessors_={...}, length=0} 
+0

你確定這不是一個錯字:strokeOpacity:1., – 2011-05-27 19:43:21

+0

我敢肯定。我試圖刪除它,以防萬一,但同樣的問題。我可以通過使用此網站上的座標示例來使Polyline工作http://code.google.com/apis/maps/documentation/javascript/overlays.html#Polylines – Colin 2011-05-27 20:05:08

+0

在該示例中,strokeOpacity爲「1.0」 ,而不是「1」。就像你上面的代碼一樣。無論它可能不相關,它只是立即展開。 – 2011-05-27 20:10:31

回答

0

我能夠通過設置一個100毫秒的超時,以防止MVCArray,因此被髮送到折線,直到地理編碼器已經完成地理編碼解決我的問題。