Wenn du in deiner Web-Applikation die GPS- bzw. Geo-Koordinaten per Javascript benötigst, dann erfährst du hier, wie das geht!
Geo-Koordinaten auslesen
var txtGeoBrowser = document.getElementById("txtGeoBrowser");
function getLocationFromBrowser() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
txtGeoBrowser.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
txtGeoBrowser.innerHTML = "Latitude: " + position.coords.latitude + " (Breitengrad)<br>Longitude: " + position.coords.longitude + " (Längengrad)";
}
Vollständiger HTML-Code
<html>
<body>
<button onclick="getLocationFromBrowser()">Lese Koordinaten</button>
<p id="txtGeoBrowser">(Werte erscheinen hier)</p>
</body>
<script>
var txtGeoBrowser = document.getElementById("txtGeoBrowser");
function getLocationFromBrowser() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
txtGeoBrowser.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
txtGeoBrowser.innerHTML = "Latitude: " + position.coords.latitude + " (Breitengrad)<br>Longitude: " + position.coords.longitude + " (Längengrad)";
}
</script>
</html>