Get latitude and longitude
Press the button to request location permission, then display the result or a helpful error message.
What you will learn
- How a user action starts a location request
- How to read latitude and longitude
- How to show a clear error without exposing private data
- Latitude
- -
- Longitude
- -
Location is sensitive information, so the browser asks for permission. A page should explain why it needs location and should continue to work when the user chooses not to share it. HTTPS is also required in most production contexts.