Geolocation

Using the Geolocation API we can ask the browser for the user’s position coordinates.

The window.navigator property exposed by browsers points to a Navigator object which is a container object that makes a lot of Web Platform APIs available to us.

The browser exposes a navigator.geolocation object, through which we’ll do all the geolocation operations. It’s only available on pages served using HTTPS, for security purposes, and it’s available on all modern browsers.

Since window is the global object, we can access navigator without specifying window.navigator

navigator.geolocation

Let’s see how to use it.

Lessons in this unit:

0: ▶︎ Introduction
1: Getting the user's position
2: Watching the position for changes
3: If the user denies the position
4: Adding more options
Want to learn more? Check out our courses