-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeoloc.js
37 lines (35 loc) · 1.36 KB
/
geoloc.js
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
"use strict";
console.log("I am Alive! - geoloc.js")
document.getElementById('meinButton').addEventListener('click', holePosition);
function holePosition() {
if (navigator.geolocation) {
document.getElementById("geoSupported").innerText = "OK - Geolocation wird unterstützt!";
let options = {
enableHighAccuracy: true
};
navigator.geolocation.getCurrentPosition(showPosition, showError, options);
} else {
document.getElementById("geoSupported").innerText = "Geolocation nicht unterstützt!";
}
}
function showPosition(position) {
document.getElementById("breite").innerHTML = 'Breitengrad: ' + position.coords.latitude;
document.getElementById("laenge").innerHTML = 'Längengrad: ' + position.coords.longitude;
document.getElementById("accuracy").innerHTML = 'Genauigkeit: ' + position.coords.accuracy;
}
function showError(error) {
switch (error.code) {
case error.PERMISSION_DENIED:
alert('Abfrage der Geoposition untersagt.');
break;
case error.POSITION_UNAVAILABLE:
alert('Es sind keine Geopositionsdaten verfügbar.');
break;
case error.TIMEOUT:
alert('Timeout überschritten.');
break;
default:
alert('Unbekannter Fehler');
break;
}
}