我在我的项目中使用谷歌地图,我自定义它用于创建和绘制多边形和多边形,但我不保存形状,现在我想在地图上创建多边形并将其保存在我的数据库中,我的问题是:如何在我的数据库中保存多边形坐标?
我的代码:
function initialize() {
var mapOptions = {
zoom: 14,
minZoom: 14,
maxZoom: 19,
center: new google.maps.LatLng(35.696282, 51.422946),
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
scaleControl: true,
streetViewControl: false
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
drawingManager = new google.maps.drawing.DrawingManager({
drawingMode: google.maps.drawing.OverlayType.POLYGON,
drawingControl: true,
drawingControlOptions: {
position: google.maps.ControlPosition.TOP_CENTER,
drawingModes: [/*google.maps.drawing.OverlayType.CIRCLE, google.maps.drawing.OverlayType.RECTANGLE, */google.maps.drawing.OverlayType.POLYLINE, google.maps.drawing.OverlayType.POLYGON]
},
polygonOptions: {
editable: true
}
});
drawingManager.setMap(map);
google.maps.event.addListener(drawingManager, "overlaycomplete", function (event) {
if (event.type != google.maps.drawing.OverlayType.MARKER) {
drawingManager.setDrawingMode(null);
var newShape = event.overlay;
newShape.type = event.type;
google.maps.event.addListener(newShape, 'click', function () {
setSelection(newShape);
});
setSelection(newShape);
}
});
google.maps.event.addListener(drawingManager, 'drawingmode_changed', clearSelection);
google.maps.event.addListener(map, 'click', clearSelection);
//delete selected shape
google.maps.event.addDomListener(document.getElementById('deleteShape'), 'click', deleteSelectedShape);
}
答案 0 :(得分:0)
var len = shape.getPath().getLength();
var htmlStr = "";
for (var i = 0; i < len; i++) {
console.log(shape.getPath().getAt(i).toUrlValue(7));
}