# Location plugin

Source: https://saastostore.com/plugins/geolocation

This plugin lets the standard `navigator.geolocation` code of your website work inside your app. There's no new API to learn: the code you already use in a browser keeps running. The plugin declares the location permissions, which the app can't use without.

## Set it up

1. **Add the plugin** In your project's plugin library, add Location, then launch a new build.
2. **Ask at the right moment** The system prompt appears the first time your site asks for a position. Call it from a button, after explaining why.
3. **Declare it in the stores** Location counts as personal data. Mention it in Data safety on Google Play and App Privacy on the App Store.

## Code

```js
navigator.geolocation.getCurrentPosition(
  (position) => {
    const { latitude, longitude } = position.coords;
    showStoresNear(latitude, longitude);
  },
  (error) => showManualSearch(error.message),
  { enableHighAccuracy: true, timeout: 10000 },
);
```

## What it adds to your app

| System | Added | Scope |
| --- | --- | --- |
| Android | `ACCESS_COARSE_LOCATION`, `ACCESS_FINE_LOCATION` | While the app is open |
| iOS | `NSLocationWhenInUseUsageDescription` | While the app is open |

Location works while the app is open. Background tracking isn't part of this plugin.

> On iOS, Location needs native navigation (Shell V2). Without the plugin, these permissions aren't declared and your site's request fails.

## Prompt for AI builders

**Prompt for Lovable, Bolt or Base44**

```text
On [PAGE], add a button that says why I need the location, then calls navigator.geolocation.getCurrentPosition.

Handle a refusal or an error by showing a manual search. Never ask for the location when the page loads. Use a timeout of 10 seconds.
```

Replace the value in [BRACKETS].

## Frequently asked questions

### Does it work in the background?

No. Location works while the app is open.

### Does it use a new JavaScript API?

No. It's the standard navigator.geolocation of browsers, so the same code works on your website and in the app.

### Why do I need to declare location in the stores?

Google Play and the App Store both ask you to declare the personal data your app accesses, and location is on the list.

### A person refused. Can I ask again?

The system doesn't show the prompt again after a firm refusal. Offer a manual search, and tell them they can allow it in the phone's settings.
