@capacitor/geolocation
The Geolocation API provides simple methods for getting and tracking the current position of the device using GPS, along with altitude, heading, and speed information if available.
Install
npm install @capacitor/geolocation
npx cap sync
iOS
Apple requires privacy descriptions to be specified in Info.plist
for location information:
NSLocationAlwaysUsageDescription
(Privacy - Location Always Usage Description
)NSLocationWhenInUseUsageDescription
(Privacy - Location When In Use Usage Description
)
Read about Configuring Info.plist
in the iOS Guide for more information on setting iOS permissions in Xcode
Android
This API requires the following permissions be added to your AndroidManifest.xml
:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />
The first two permissions ask for location data, both fine and coarse, and the last line is optional but necessary if your app requires GPS to function. You may leave it out, though keep in mind that this may mean your app is installed on devices lacking GPS hardware.
Read about Setting Permissions in the Android Guide for more information on setting Android permissions.
Variables
This plugin will use the following project variables (defined in your app's variables.gradle
file):
playServicesLocationVersion
version ofcom.google.android.gms:play-services-location
(default:21.0.1
)