capacitor-enable-gps-plugin
v0.1.2
Published
Capacitor plugin for requesting users to enable Android GPS/location services.
Downloads
483
Maintainers
Readme
capacitor-enable-gps-plugin
Capacitor plugin for asking Android users to enable GPS/location services.
The Android implementation uses Google Play Services SettingsClient to show the native location settings resolution dialog when possible. If the dialog cannot be shown, it opens the Android location settings screen and resolves with the current enabled state when the user returns.
Install
npm install ./capacitor-enable-gps-plugin
npx cap sync androidUsage
import { EnableGps } from 'capacitor-enable-gps-plugin';
const current = await EnableGps.isEnabled();
if (!current.enabled) {
const result = await EnableGps.requestEnable({
highAccuracy: true,
alwaysShow: true,
});
console.log('Location enabled:', result.enabled);
}API
isEnabled() => Promise<{ enabled: boolean }>
requestEnable(options?: {
highAccuracy?: boolean;
alwaysShow?: boolean;
}) => Promise<{ enabled: boolean }>Notes
- Android only: iOS does not provide the same app-triggered GPS enable dialog.
- This plugin checks whether either the GPS or network location provider is enabled.
- Android permissions are declared in the plugin manifest, but your app should still request runtime location permission separately before reading location.
