forked from mihailescu2m/powerwall_monitor
-
Notifications
You must be signed in to change notification settings - Fork 3
/
location.html
50 lines (42 loc) · 1.91 KB
/
location.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
<html>
<head>
<title>Find My GPS Coordinates</title>
</head>
<body>
<button id = "find-me">Show My GPS Coordinates</button><br/>
<p id = "status"></p>
<a id = "map-link" target="_blank"></a>
<p id = "latitude"></p>
<p id = "longitude"></p>
<script>
function geoFindMe() {
const status = document.querySelector('#status');
const mapLink = document.querySelector('#map-link');
const lat = document.querySelector('#latitude');
const lon = document.querySelector('#longitude');
mapLink.href = '';
mapLink.textContent = '';
function success(position) {
const latitude = position.coords.latitude;
const longitude = position.coords.longitude;
status.textContent = '';
mapLink.href = `https://www.google.com/maps/@${latitude},${longitude},16z/`;
// mapLink.href = `https://www.openstreetmap.org/#map=18/${latitude}/${longitude}`;
mapLink.textContent = `MAP Link: Latitude: ${latitude} - Longitude: ${longitude}`;
lat.textContent = `latitude = ${latitude}`;
lon.textContent = `latitude = ${longitude}`;
}
function error() {
status.textContent = 'Unable to retrieve your location';
}
if(!navigator.geolocation) {
status.textContent = 'Geolocation is not supported by your browser';
} else {
status.textContent = 'Locating…';
navigator.geolocation.getCurrentPosition(success, error);
}
}
document.querySelector('#find-me').addEventListener('click', geoFindMe);
</script>
</body>
</html>