我知道,這個問題可能會被重複如何保存地圖繪製狀態(多邊形,折線,標記,標記)
How to save map drawing state (Polygon, Polyline, Markers)
但只有回答能夠體現出圓如,何談其他形狀
要使用的下一個折線例如如何檢索點儲存到陣列以將其顯示 我有這樣的代碼,它很好地工作
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: { lat: -34.397, lng: 150.644 },
zoom: 8
});
var drawingManager = new google.maps.drawing.DrawingManager({
drawingMode: google.maps.drawing.OverlayType.MARKER,
drawingControl: true,
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
drawingModes: ['marker', 'circle', 'polygon', 'polyline', 'rectangle']
},
markerOptions: { icon: 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png' },
circleOptions: {
fillColor: '#ffff00',
fillOpacity: 1,
strokeWeight: 5,
clickable: false,
editable: true,
zIndex: 1
}
});
drawingManager.setMap(map);
var circles = [];
google.maps.event.addDomListener(drawingManager, 'circlecomplete', function (circle) {
circles.push(circle);
});
google.maps.event.addDomListener(savebutton, 'click', function() {
document.getElementById("savedata").value = "";
for (var i = 0; i < circles.length; i++) {
var circleCenter = circles[i].getCenter();
var circleRadius = circles[i].getRadius();
document.getElementById("savedata").value += "circle((";
document.getElementById("savedata").value +=
circleCenter.lat().toFixed(3) + "," + circleCenter.lng().toFixed(3);
document.getElementById("savedata").value += "), ";
document.getElementById("savedata").value += circleRadius.toFixed(3) + ")\n";
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=MyKey&libraries=drawing&callback=initMap"
async defer></script>
的問題是當我試圖通過增加這部分代碼以檢索折線的座標:
var Lines = [];
google.maps.event.addDomListener(drawingManager, 'polylinecomplete', function (polyline) {
Lines.push(Lines);
});
google.maps.event.addDomListener(savebutton, 'click', function() {
document.getElementById("savedata").value = "";
for (var i = 0; i < Lines.length; i++) {
document.getElementById("savedata").value += "Line((";
document.getElementById("savedata").value +=
Lines[i].getPath().getArray().toString();
document.getElementById("savedata").value += "),";
}
});
它給我的錯誤Line2.aspx:91遺漏的類型錯誤:行[I] .getPath不是一個函數(...)
相關的問題:[GMAP繪製工具來圖像jpeg(靜態地圖URL)](http://stackoverflow.com/questions/31277220/gmap-drawing-tools-to-image-jpeg-static-map-url) – geocodezip