Free tutorials for Java, Eclipse and Web programming



Follow me on twitter

6. Geolocation

HTML5 supports a geolocation API. For example you can read your currently geolocation and display this postion on a google map via the following code HTML page.

			<html>
<head>
<script type="text/javascript">
    if (navigator.geolocation) {
    	navigator.geolocation.getCurrentPosition(function(position) {  
      		alert("Latitude: " + position.coords.latitude);
      		alert("Longitude: ' + position.coords.longitude);
    	});
      navigator.geolocation.getCurrentPosition(function(position) {  
        document.location.href =
          "http://maps.google.com/maps?q=" 
          + position.coords.latitude + ",+" 
          + position.coords.longitude
          + "+(My%20position)&iwloc=A&hl=en";
      });
    }
  </script>
</head>
<body>
</body>
</html>