
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
How to handle Geolocation errors in HTML5?
HTML5 Geolocation API lets you share your location with your favorite websites. A JavaScript can capture your latitude and longitude and can be sent to backend web server and do fancy location-aware things like finding local businesses or showing your location on a map.
Geolocation is complicated, and it is very much required to catch any error and handle it gracefully.
The geolocations methods getCurrentPosition() and watchPosition() make use of an error handler callback method which gives PositionError object. This object has following two properties −
Property | Type | Description |
Code | Number | Contains a numeric code for the error. |
message | String | Contains a numeric code for the error. |
The following table describes the possible error codes returned in the PositionError object.
Code | Constant | Description |
0 | UNKNOWN_ERROR | The method failed to retrieve the location of the device due to an unknown error. |
1 | PERMISSION_DENIED | The method failed to retrieve the location of the device because the application does not have permission to use the Location Service. |
2 | POSITION_UNAVAILABLE | The location of the device could not be determined. |
3 | TIMEOUT | The method was unable to retrieve the location information within the specified maximum timeout interval. |
Here’s how you can make use of the PositionError object. The errorHandler method is a callback method −
- Related Articles
- How to handle errors in HTML5 Web Workers?
- How to use geolocation coordinates in HTML5?
- How to find position with HTML5 Geolocation?
- How to handle errors within WaitGroups in Golang?
- HTML5 Geolocation in Safari 5
- How to use HTML5 Geolocation Latitude/Longitude API?
- How to handle errors in middleware C# Asp.net Core?
- How to use HTML5 GeoLocation API with Google Maps?
- How to handle errors while working with Navigation in ReactNative?
- HTML5 Geolocation without SSL connection
- Best practices to handle errors in node-red
- Chrome and HTML5 GeoLocation denial callback
- How to best display HTML5 geolocation accuracy on a Google Map?
- How to handle the errors generated while deserializing a JSON in Java?
- How can MySQL handle the errors during trigger execution?
