-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgeoloc.html
More file actions
30 lines (28 loc) · 724 Bytes
/
geoloc.html
File metadata and controls
30 lines (28 loc) · 724 Bytes
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
<html>
<head>
<title>Geolocation</title>
</head>
<body>
<!-- Paragraph to display the user's current location -->
<p id="location"></p>
</body>
<script>
// Get current position
navigator.geolocation.getCurrentPosition(function(pos){
// Display the latitude and longitude on the paragraph
document.getElementById('location').innerHTML = pos.coords.latitude + ", " + pos.coords.longitude;
});
// Check for change in position
id = navigator.geolocation.watchPosition(
// On success
function(pos){
// Do something when the location is changed
console.log('Changed');
},
// On error
function(){
console.log('Error');
}
);
</script>
</html>