HTML5 Geolocation API


Some of the Geolocation interfaces, properties, and methods are given here.

Interfaces

Geolocation The Geolocation is the main object in the API. It encapsulates all the methods and properties needed to obtain the devices and user’s location information if permission is granted.
PositionOptions The getCurrentPosition and watchPosition methods accept PositionOptions objects as their third argument.
Position Same as Coordinates
Coordinates This object represents the geographic location coordinates.
PositionError The error information is the geographical information that cannot be obtained.


Methods of Geolocation Interface

clearWatch This method when used will stop the script from listening for new updates from the geographical location.
getCurrentPosition Get the current location as latitude and longitude coordinates.
watchPosition When you implement this method, Geolocation will begin watching for updates from the client.


The getCurrentPosition Method
The getCurrentPosition method returns an object if it is successful. The latitude, longitude, and accuracy properties are always returned. The other properties below are returned if available.

Property Value Unit Description
coords.latitude double degrees The latitude as a decimal number
coords.longitude double degrees The longitude as a decimal number
coords.accuracy double meters The accuracy of position
coords.altitude double or null meters The altitude in meters above the mean sea level
coords.altitudeAccuracy double or null meters The altitude accuracy of position
coords.heading double or null degrees clockwise The heading as degrees clockwise from North
coords.speed double or null meters/second The speed in meters per second
timestamp DOMTimeStamp like the Date object The date/time of the response

Demonstration
The following demonstration shows how the HTML5 script is displayed on the Web.