
- 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 use HTML5 Geolocation Latitude/Longitude API?
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.
The geolocation APIs work with a new property of the global navigator object ie. Geolocation object.
Example
You can try to run the following code to find the current location using the Geolocation API, with Latitude and Longitude coordinates
<!DOCTYPE HTML> <html> <head> <script type="text/javascript"> function showLocation(position) { var latitude = position.coords.latitude; var longitude = position.coords.longitude; alert("Latitude : " + latitude + " Longitude: " + longitude); } function errorHandler(err) { if(err.code == 1) { alert("Error: Access is denied!"); } else if( err.code == 2) { alert("Error: Position is unavailable!"); } } function getLocation(){ if(navigator.geolocation){ // timeout at 60000 milliseconds (60 seconds) var options = {timeout:60000}; navigator.geolocation.getCurrentPosition (showLocation, errorHandler, options); } else{ alert("Sorry, browser does not support geolocation!"); } } </script> </head> <body> <form> <input type="button" onclick="getLocation();" value="Get Location"/> </form> </body> </html>
- Related Articles
- How do I get an address latitude-longitude using HTML5 Geolocation or Google API?
- How to use HTML5 GeoLocation API with Google Maps?
- How to use geolocation coordinates in HTML5?
- How to get current location latitude and longitude in Android?
- How to complete address from latitude and longitude on Android?
- How to get the current location latitude and longitude in iOS?
- How to find the latitude and longitude from address in Android?
- How to get the longitude and latitude of a city using Python?
- How to find position with HTML5 Geolocation?
- How to handle Geolocation errors in HTML5?
- How to get a complete address from latitude and longitude on Android Kotlin?
- HTML5 Geolocation without SSL connection
- HTML5 Geolocation in Safari 5
- Latitude and longitude of the user's position in JavaScript?
- How can I find the latitude and longitude from address on Android using Kotlin?

Advertisements