@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:
NSLocationAlwaysAndWhenInUseUsageDescription(Privacy - Location Always and When In Use Usage Description)NSLocationWhenInUseUsageDescription(Privacy - Location When In Use Usage Description)
[!NOTE] This Capacitor plugin does not support background geolocation directly. However, it relies on
ion-ios-geolocation, which can report location in the background. As a result, Apple requires you to include aNSLocationAlwaysAndWhenInUseUsageDescriptionentry in yourInfo.plist. Since this permission prompt won’t appear to users, you can safely use the same description string as forNSLocationWhenInUseUsageDescription.
Read about Configuring Info.plist in the iOS Guide for more information on setting iOS permissions in Xcode
Android
This plugin requires the following permissions be added to your AndroidManifest.xml:
<!-- Geolocation Plugin -->
<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" />