-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
32 lines (26 loc) · 937 Bytes
/
index.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
<!DOCTYPE html>
<html>
<body>
<p>Click in the button to get your coordinates (long/lat).</p>
<button onclick="getLocation()">Find my Location</button>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser, try Mozila Firefox, Chrome, Brave, etc.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
</script>
</body>
</html>
<!-- Fontes
https://developer.mozilla.org/pt-BR/docs/Web/API/Geolocation/getCurrentPosition -
https://developer.mozilla.org/pt-BR/docs/Web/API/Geolocation_API
https://www.w3schools.com/html/tryit.asp?filename=tryhtml5_geolocation -->