Web Technologies - HTML5

Back to Course

Lesson Description

Lession - #588 HTML5 Geolocation

HTML5 Geolocation API permits you to share your location along with your favorite web sites. A JavaScript will capture your latitude and longitude and can be sent to backend internet server and do fancy location-aware things like finding local businesses or showing your location on a map.

The geolocation Apis work with a new property of the world navigator object ie. Geolocation object which can be created as follows −

var geolocation = navigator.geolocation;

The geolocation object is a service object that enables widgets to retrieve information about the geographic location of the device.

Geolocation methods
The geolocation object provides the following

1 getCurrentPosition(>
This method retrieves this geographic location of the user.

2 watchPosition(>
This method retrieves periodic updates about this geographic location of the device.

3 clearWatch(>

This method cancels an ongoing watchPosition call


      <meta charset = "UTF-8"> 
      <title> HTML5 Example< /title> 
	  function getLocation(>
{ var geolocation = navigator.geolocation; geolocation.getCurrentPosition(showLocation, errorHandler>
; } </srcipt> </head> </body> <h1>Gealocation</h1> </body> </html>

Try it here