HTML5 Geolocation

06.08.2012 | HTML5

Erfragt allerdings die Erlaubnis vom User: <!DOCTYPE html> <html> <body> <p id="demo">Click the button to get your coordinates:</p> <button onclick="getLocation()">

Erfragt allerdings die Erlaubnis vom User:



<!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to get your coordinates:</p>
<button onclick="getLocation()">Try It</button>
<script>
var x=document.getElementById("demo");
function getLocation()
  {Try
  if (navigator.geolocation)
    {
    navigator.geolocation.getCurrentPosition(showPosition);
    }
  else{x.innerHTML="Geolocation is not supported by this browser.";}
  }
function showPosition(position)
  {
  x.innerHTML="Latitude: " + position.coords.latitude + 
  "<br />Longitude: " + position.coords.longitude; 
  }
</script>

Bsp. aus http://www.w3schools.com/html5/html5_geolocation.asp

Analyse

Entwurf

Development

Launch