What is the Geolocation API?
In HTML5, the Geolocation API is used to obtain the user’s geographical location.
Since this can compromise user privacy, the option is not available unless the user approves it.
Using HTML Geolocation
The Geolocation API’s main method is getCurrentPosition, which retrieves the current geographic location of the user’s device.
showLocation (mandatory): Defines the callback method that retrieves location information.
ErrorHandler(optional): Defines the callback method that is invoked when an error occurs in processing the asynchronous call.
Options (optional): Defines a set of options for retrieving the location information.
User location can be presented in two ways: Geodetic and Civic.
- The geodetic way to describe position refers directly to latitude and longitude.
- The civic representation of location data is presented in a format that is more easily read and understood by the average person.
Each parameter has both a geodetic and a civic representation: