🖥️Browser

Compass supports HTML5 Geolocation API with the compass-geolocator-browser artifact. The artifact supports JS and WASM targets.

Geolocation in the browser requires the user to provide permission. This is handled automatically when you start tracking or attempt to get the current location.

If your project supports both Browser and other targets, you need to configure your setup to provide a Geolocator for each platform. Check out Mixed platformsfor more information.

Usage

Follow these steps to create a Geolocator

Create Locator

Geolocator is powered by the Locator object:

val locator: Locator = createBrowserLocator()
val locator: Locator = Locator.browser()

Create Geolocator

Then you can use that to create the Geolocator object:

val geolocator: Geolocator = Geolocator(locator)

Or you can use an extension function to skip the Locator step:

val geolocator: Geolocator = Geolocator()
val geolocator: Geolocator = BrowserGeolocator()
val geolocator: Geolocator = Geolocator.browser()

Permissions

Nothing extra is required to setup permissions for the browser.

When you attempt to get the location, the browser will show a prompt to the user. They can allow, deny, or do one of those permanently.

Get location

Now you can follow the steps in Geolocator

Last updated