react-native-fused-location
Get the finest location on Android using Fused API.
I created this react native module with an inspiration that none of react native's location libraries use the newer Fused API to get location. According to google, it is the most accurate way to get location in an Android device and judges by itself when to use GPS or cell towers/wifi. Thus, it works with both.
Install
npm install react-native-fused-location --save
or
yarn add react-native-fused-location
Automatic Link.
react-native link react-native-fused-location
Manual Link.
• in android/app/build.gradle:
dependencies {
...
compile "com.facebook.react:react-native:+" // From node_modules
+ compile project(':react-native-fused-location')
}
• in android/settings.gradle
:
...
include ':app'
+ include ':react-native-fused-location'
+ project(':react-native-fused-location').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fused-location/android')
• in MainApplication.java:
+ import com.mustansirzia.fused.FusedLocationPackage;
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
...
+ new FusedLocationPackage(),
...
new MainReactPackage()
);
}
Migration to AndroidX. - BREAKING CHANGE in 1.0.0
.
• Version 1.0.0
and above of this libary now makes use of AndroidX namespace instead of the legacy android support library namespace. If your app hasn't migrated to AndroidX yet, consider doing so or instead use an older version of this library such as 0.5.1
. React Native 0.59
uses AndroidX.
To enable AndroidX add these two lines in your android/gradle.properties
file.
android.useAndroidX=true
android.enableJetifier=true
If this doesn't work out. Check out this official guide from Google.
A guide more specific to React Native would be here.
Permissions.
Add this to your AndroidManifest.xml
:
...
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
...
<permission
android:name="android.permission.ACCESS_COARSE_LOCATION"
android:protectionLevel="signature" />
<permission
android:name="android.permission.ACCESS_FINE_LOCATION"
android:protectionLevel="signature"/>
...