-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw-polygon-get-coordinates.html
92 lines (85 loc) · 2.21 KB
/
draw-polygon-get-coordinates.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<html>
<head>
<title>Google Maps Draw Polygon Get Coordinates</title>
<script
type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBnY3rbBH--hIiQDkw25hFpFMKCn48MlSk"
></script>
<script type="text/javascript">
var draggablePolygon;
function InitMap() {
var location = new google.maps.LatLng(28.620585, 77.228609);
var mapOptions = {
zoom: 7,
center: location,
mapTypeId: google.maps.MapTypeId.RoadMap,
};
var map = new google.maps.Map(
document.getElementById("map-canvas"),
mapOptions
);
var shapeCoordinates = [
new google.maps.LatLng(28.525416, 79.870605),
new google.maps.LatLng(27.190518, 77.530518),
new google.maps.LatLng(29.013807, 77.67334),
];
// Construct the polygon
draggablePolygon = new google.maps.Polygon({
paths: shapeCoordinates,
draggable: true,
editable: true,
strokeColor: "",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#ADFF2F",
fillOpacity: 0.5,
});
draggablePolygon.setMap(map);
google.maps.event.addListener(
draggablePolygon,
"dragend",
Getpolygoncoordinates
);
google.maps.event.addListener(
draggablePolygon.getPath(),
"insert_at",
Getpolygoncoordinates
);
google.maps.event.addListener(
draggablePolygon.getPath(),
"remove_at",
Getpolygoncoordinates
);
google.maps.event.addListener(
draggablePolygon.getPath(),
"set_at",
Getpolygoncoordinates
);
}
function Getpolygoncoordinates() {
var len = draggablePolygon.getPath().getLength();
var strArray = "";
for (var i = 0; i < len; i++) {
strArray +=
draggablePolygon.getPath().getAt(i).toUrlValue(5) + "<br>";
}
document.getElementById("info").innerHTML = strArray;
}
</script>
</head>
<body onload="InitMap();Getpolygoncoordinates();">
<h2>Google Maps Draw Polygon Get Coordinates - Demo</h2>
<div id="map-canvas" style="height: 400px; width: auto"></div>
<h4>Updated Coordinates (X,Y)</h4>
<div
id="info"
style="
position: absolute;
color: red;
font-family: Arial;
height: 200px;
font-size: 12px;
"
></div>
</body>
</html>