我將googlemap上標記的多邊形的座標存儲到mysql數據庫中。我可以在編輯頁面中繪製該多邊形。我的問題是,當我通過拖動點編輯地圖時,如何獲得新的座標。我讀谷歌地圖文檔,用戶可編輯的形狀,但我不能得到它。請幫幫我。編輯google地圖後獲取座標
在此先感謝 iijb
我將googlemap上標記的多邊形的座標存儲到mysql數據庫中。我可以在編輯頁面中繪製該多邊形。我的問題是,當我通過拖動點編輯地圖時,如何獲得新的座標。我讀谷歌地圖文檔,用戶可編輯的形狀,但我不能得到它。請幫幫我。編輯google地圖後獲取座標
在此先感謝 iijb
Here is an example map是獲取路徑(不是路徑,因爲折線沒有這樣的方法)的文檔,並使用結果在文本框中創建XML 。
這個怎麼樣
var map;
var coords = [];
var lats = [];
var lngs = [];
var myMarkers = [];
var myPoly;
function initialize() {
var latlng = new google.maps.LatLng(17.397821, 78.479354);
var mapOptions = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.TERRAIN
}
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
addEventListener_marker();
}
function addEventListener_marker() {
google.maps.event.addListener(map, 'click', function (e) {
coords.push(e.latLng);
lats.push(e.latLng.lb);
lngs.push(e.latLng.mb);
placeMarker(e.latLng, map);
});
}
function placeMarker(position, map) {
var mark = new google.maps.Marker({
position: position,
map: map,
draggable: false
});
myMarkers.push(mark);
}
function createPoly() {
polyOptions = {
path: coords,
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#FF6803",
fillOpacity: '0.25',
draggable: true,
editable: true
}
myPoly = new google.maps.Polygon(polyOptions);
myPoly.setMap(map);
google.maps.event.addListener(myPoly, 'click', isWithinPoly);
markerCoords();
//removeEventListener();
clearOverlays();
}
function markerCoords() {
var curLatLng = [];
curLatLng = myPoly.getPath().getArray();
$("#info").append("coordinates are: Latitude: " + curLatLng + "<br/>");
//google.maps.event.addListener(myPoly, 'shape_changed', function() {
google.maps.event.addListener(myPoly, 'dragend', function() {
//alert("drag end");
var curLatLng;
curLatLng = myPoly.getPath().getArray();
$("#info").append("coordinates are: Latitude: " + curLatLng + "<br/>");
});
}
function removeEventListener() {
//google.maps.event.clearListeners(map, 'bounds_changed');
}
function clearOverlays() {
setAllMap(null);
}
function setAllMap(map) {
for (var i = 0; i < myMarkers.length; i++) {
myMarkers[i].setMap(map);
}
}
function isWithinPoly(event) {
var isWithinPolygon = google.maps.geometry.poly.containsLocation(event.latLng, this);
}
google.maps.event.addDomListener(window, 'load', initialize);
怎麼辦用戶編輯多邊形?拖動標記?那麼marker.getPosition()是你的朋友 – slawekwin