- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
HTML5 Geolocation in Safari 5
HTML5 Geolocation API lets you share your location with your favorite web sites. A JavaScript can capture your latitude and longitude, can be sent to backend web server, and do fancy location-aware things like finding local businesses or showing your location on a map.
Example
Let us see how to get the current position −
<!DOCTYPE HTML> <html> <head> <script> 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
- HTML5 geolocation 'permission denied' error in Mobile Safari
- Detect folders in Safari with HTML5
- HTML5 Geolocation without SSL connection
- How to use geolocation coordinates in HTML5?
- How to handle Geolocation errors in HTML5?
- Chrome and HTML5 GeoLocation denial callback
- HTML5 date field and placeholder text in Safari
- Geolocation HTML5 enableHighAccuracy True, False or What?
- How to find position with HTML5 Geolocation?
- Error codes returned in the PositionError object HTML5 Geolocation
- Raise the Mobile Safari HTML5 application cache limit?
- How to use HTML5 Geolocation Latitude/Longitude API?
- Error Codes returned in the PositionError object in HTML5 Geolocation
- How to use HTML5 GeoLocation API with Google Maps?
- Getting Safari to recognize HTML 5

Advertisements