HTML5 Geolocation

Posted in HTML5, 06.08.2012 20:08

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