-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmap_radius.html
More file actions
83 lines (68 loc) · 2.55 KB
/
map_radius.html
File metadata and controls
83 lines (68 loc) · 2.55 KB
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
<!-- don't remove this file, it's here for testing purposes -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Circle with Polygon Testing</title>
<script src="https://maps.googleapis.com/maps/api/js?key=<YOUR_KEY_HERE>&callback=initMap"
async></script>
<script>
const d2r = Math.PI / 180; // degrees to radians
const r2d = 180 / Math.PI; // radians to degrees
const earthRadius = 6371; // in km
function initMap() {
// const hqPoint = {lat: 45.8293, lng: 15.9793}; // zagreb
// const hqPoint = {lat: 64.9841821, lng: -18.1059013}; // iceland
// const hqPoint = {lat: -36.852095, lng: 174.7631803}; // auckland, new zealand
const hqPoint = {lat: 45.46, lng: 16.31}; // petrinja eq
const points = 13
const radius = 50 // km
const map = new google.maps.Map(document.getElementById("map"), {
zoom: 8,
center: hqPoint
});
new google.maps.Marker({
position: hqPoint,
map: map
});
drawCircle(hqPoint.lat, hqPoint.lng, map, points, radius);
}
function drawCircle(lat, lng, map, points, radius) {
// find the radius in lat/lon
const latR = (radius / earthRadius) * r2d;
const lngR = latR / Math.cos(lat * d2r);
const latLngPoints = [];
for (let i = 0; i < points + 1; i++) {
const theta = Math.PI * (i / (points / 2));
const ey = lat + (latR * Math.sin(theta)); // center b + radius y * sin(theta)
const ex = lng + (lngR * Math.cos(theta)); // center a + radius x * cos(theta)
latLngPoints.push({lat: ey, lng: ex});
}
new google.maps.Polyline({
path: latLngPoints,
strokeColor: '#000',
strokeWeight: 2,
}).setMap(map);
}
</script>
<style>
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
</body>
</html>