How to install Geolocation in react-native v0.63 the easy way 💪
A step-by-step guide on how to install @react-native-community/geolocation
The react-native team recently launched react-native v0.6. Surprisingly, the geolocation API was moved to @react-native-community/geolocation, causing a bit of change in how it is used due to its installation. In this article, I’m going to show you how to install it and how to solve a common problem whilst installing it.
Setting up our project
Follow this link to setup your development environment for android, then switch to React Native CLI Quickstart
.
Create a new React Native project
npx react-native init MyGeolocation
cd MyGeolocation
Run the line of code in your terminal to start your project npx react-native run-android
Let’s get started 🔥
Install @react-native-community/geolocation
for android
run yarn add @react-native-community/geolocation
or npm install @react-native-community/geolocation
Add user permission to AndroidManifest.xml
Go to AndroidManifest.xml in android/app/src/main/AndroidManifest.xml
and add or check here
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Restart your project
Run npx react-native run-android
in your terminal
💎 Tip
Note: you might get this error in your terminal
Task :app:mergeDexDebug Failed
this usually occur when you have imported a lot of packages which is unable to fit in a yaml file, which then causes a problem for the multidex builder.
dependencies{
compile 'com.android.support:multidex:1.0.1'
}
android{
defaultConfig {
multiDexEnabled true
}
}
Now re-run npx react-native run-android
and tadaaa 🎉
Is that all?
Yeah! Yeah!! Yeah!!!
Like and share.