1

我想在谷歌地圖上用多段線作爲它們之間的連接繪製標記。但是 我無法在Google地圖上顯示我的多段線。我已將多段線和地圖初始化爲全局變量。標記正在顯示,但折線沒有呈現。谷歌地圖API v3 Polyline在更新時不顯示

function initialize() { 
var mapOptions = { 
    zoom : 13, 
    center : oldenburg, 
    mapTypeId : google.maps.MapTypeId.ROADMAP 
}; 
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions); 
var polyOptions = { 
     strokeColor : '#FF3333', 
     strokeOpacity : 1.0, 
     strokeWeight : 3 
    }; 
    path = new google.maps.Polyline(polyOptions); 
    path.setMap(map); 
} 
function addPlaces(orte) { 

for (var i = 0; i < orte.length; i++) { 
    var ort = toLatLng(orte[i][0], orte[i][1]); 
    path.getPath().push(ort); 

    marker = new google.maps.Marker({ 
     position : ort, 
     title : '#' + orte[i][2], 
     icon : image, 
     map : map 
    }); 
} 

} 

回答

2

嘗試和實例折線時指定路徑:

例: 谷歌例如座標

var flightPlanCoordinates = [ 
    new google.maps.LatLng(37.772323, -122.214897), 
    new google.maps.LatLng(21.291982, -157.821856), 
    new google.maps.LatLng(-18.142599, 178.431), 
    new google.maps.LatLng(-27.46758, 153.027892) 
    ]; 

使用您的代碼的座標爲例

var polyOptions = { 
    path: flightPlanCoordinates, //IMPORTANT TO SET the PATH for the line to RENDER 
    strokeColor : '#FF3333', 
    strokeOpacity : 1.0, 
    strokeWeight : 3 
}; 

或as谷歌文檔示例使用以上座標:

var flightPath = new google.maps.Polyline({ 
    path: flightPlanCoordinates, 
    strokeColor: "#FF0000", 
    strokeOpacity: 1.0, 
    strokeWeight: 2 
    }); 
+0

我想寫在這裏只爲其他人誰得到了問題。我有一個巨大的數組陣列和最後一項是不是一個數字,所以它只是不顯示沒有錯誤。 – user1651804

+0

我的回答有用嗎? –

+0

謝謝你的回答,但我的問題是別的。 – user1651804