2012-09-11 27 views

回答

14

最後我找到了解決方案!問題是encodePath需要一個google.maps.LatLng對象,而不僅僅是GeoPoints

這裏是一個函數,它變成像一個以上descripted成編碼串的陣列:

function encodeLatLngPolygon(array) { 

var polyOptions = { 
strokeColor: '#000000', 
strokeOpacity: 1.0, 
strokeWeight: 3 
    } 
    poly = new google.maps.Polyline(polyOptions); 

var path = poly.getPath(); 

for(var i=0;i<array.length;i++) { 
    var xyz = new google.maps.LatLng(parseFloat(array[i][0]).toFixed(2), parseFloat(array[i][1]).toFixed(2)); 
    path.push(xyz);    

} 

var code = google.maps.geometry.encoding.encodePath(path) 

return code; 
} 

toFixed小數點用於保存字節之後降低了的數字。您可以刪除或調整此參數。