Web APIsLesson 55Free preview
Geolocation API
This lesson is part of HTML · All levels
Summary
The geolocation API allows web pages to obtain the location of a user's device, such as latitude and longitude, with the user's permission. Location is obtained by the navigator.geolocation method. getCurrentPosition(). Because of the privacy concerns, the browser always displays the permission dialog before the location is shared.
Key points
- Location is taken through navigator.geolocation.
- The browser asks the user's permission before sharing the location
- The result contains the coordinates of latitude and longitude.
- Can be used for maps, nearby searches, or weather.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.