Device Permissions1 min read
Location Services
Turn on location access for your app, choose when users are asked, use navigator.geolocation from your website, and track location in the background.
Overview
With Location Services on, your website can use the standard browser geolocation API inside the app, for example for a store finder or delivery address.
Turn it on
- Open Permissions › Device › Location Services.
- Turn on Enable Location Services.
- Choose the request timing:
- At runtime (recommended): when your website first asks for the location.
- Immediately on app launch.
- Manual JavaScript Bridge request: only when your website calls
wapp.permissions.request('location').
- Choose the platforms and write the explanation users see. On iOS, also review the location purpose string.
- Save and start a new build.
Use it from your website
javascript
async function findNearestStore() {
if (window.wapp) {
const permission = await wapp.permissions.request('location');
if (!permission.success || permission.status !== 'granted') {
return showManualAddressForm();
}
}
navigator.geolocation.getCurrentPosition(
(position) => showStoresNear(position.coords.latitude, position.coords.longitude),
() => showManualAddressForm()
);
}The same code works in a normal browser: there, the browser's own location prompt is used.
Background tracking
Location Services covers location while the app is open. To keep tracking while the app is in the background (for example for delivery drivers), use the Background Location plugin. It has its own permission texts and needs a plan that includes it.
Tips
- Ask at the moment the user wants a location-based feature, not on launch.
- Always offer a fallback, such as entering a postcode.
- Explain the benefit in the prompt: "Find the store nearest to you."