midHTML5
What is the Geolocation API?
Updated Apr 28, 2026
Short answer
An API that allows the user to provide their geographic location to web applications.
Deep explanation
Accessed via navigator.geolocation, it can return latitude and longitude. For privacy, the browser always prompts the user for permission before sharing location data.
Real-world example
A 'Store Locator' page that automatically shows the nearest physical shop to the user.
Common mistakes
- Assuming it will always work (users can deny permission or the device may lack GPS).
Follow-up questions
- Is it available on non-secure (HTTP) sites?