如何收集我们通过谷歌绘图API绘制的多边形形状的每个边缘的纬度和经度。请把我放在收集Polygon边缘的完美路径上帮助我。
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title> Region Drawing System</title>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=drawing,geometry&sensor=false"></script>
<script>
var infoWindow;
var contentString;
function initialize() {
var mapOptions = {
center : new google.maps.LatLng(42.397, -100.000),
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var 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.POLYGON
]
},
polygonOptions :{
editable: true,
draggable: true
}
});
drawingManager.setMap(map);
google.maps.event.addListener(drawingManager, 'click', showNewPath); // Passing drawingManager object is a good idea to collect edges of Polygon ?
infoWindow = new google.maps.InfoWindow();
}
function showNewPath() {
var contentString = " " //How to collect the edges of Polygon ?
infoWindow.setContent(contentString);
infoWindow.setPosition(); // How to specify the position for each edge ?
infowindow.open(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<center>
<h1> Region Drawing System</h1>
<div id="map-canvas" style="height:400px ; width:800px"></div>
<hr/>
<div id="panel">
<input id="address" type="textbox" value="">
<input type="button" value="Look UP" >
</div>
</center>
</body>
</html>
答案 0 :(得分:0)
通过以下代码。任何人都可以找到我们绘制的多边形的纬度和经度。
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title> Region Drawing System</title>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=drawing,geometry&sensor=false"></script>
<script>
var polygonShape = [];
var infoWindow = new google.maps.InfoWindow({maxWidth : 450});
var contentString;
function initialize() {
var mapOptions = {
center : new google.maps.LatLng(42.397, -100.000),
zoom: 4,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var 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.POLYGON
]
},
polygonOptions :{
editable: true,
draggable: true
}
});
drawingManager.setMap(map);
google.maps.event.addListener(drawingManager, 'polygoncomplete', function (e) {
var vert = e.getPath(); //In the method we could get the vertices of the polygon which we have drawn.
var clat = 0; // To display the infowindow.
var clng = 0; // To display the infowindow.
var contents = '</br><label><b>Region Name : </b></label><input type="text" size="20" id="region_name"/></br><label align="top"><b>Description : </b></label><textarea id="region_desc" cols="20" rows="3"></textarea><br/><input type="button" value="Save Region" onclick="getPointInfo(polygonShape);"/><br/>';
vert.forEach(function(xy, i) {
clat = xy.lat();
clng = xy.lng();
});
infoWindow.setContent(contents);
infoWindow.setPosition(new google.maps.LatLng(clat,clng));
infoWindow.open(map);
});});
infoWindow = new google.maps.InfoWindow();
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<center>
<h1> Region Drawing System</h1>
<div id="map-canvas" style="height:400px ; width:800px"></div>
<hr/>
</center>
</body>
</html>
享受上述代码。