react-native-google-location
Location acquisition through Google Play Services.
Installation
If you have not done - Install Google Play APK
Check here
Install the npm package
npm i --save react-native-google-location
Then you must install the native dependencies. You can use rnpm
to
add native dependencies automatically (you still have to add permissions to your Manifest file, see "Add Permissions and used Google API to your Project"):
rnpm link
or do it manually as described below:
Manual Installation: Add it to your android project
- In
android/settings.gradle
...include ':react-native-google-location', ':app'project(':react-native-google-location').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-google-location/android/app')
- In
android/app/build.gradle
...dependencies { ... compile project(':react-native-google-location')}
- register module (in MainActivity.java)
Newer versions of React Native
... // <--- import ...
Older versions of React Native
// <--- import
Add Permissions and used Google API to your Project
Add this to your AndroidManifest file;
// file: android/app/src/main/AndroidManifest.xml
Make sure this goes at the bottom of the <application>
tag.
Example
'use strict'; var React = ; // Import react-native-google-location; var Component AppRegistry // DeviceEventEmitter for registering of the Callback-Listener DeviceEventEmitter StyleSheet Text View = React; { superprops; // Create and Reset initial State Longitude (lng) and Latitude (lat) thisstate = lng: 00 lat: 00 ; if !thisevEmitter // Register Listener Callback - has to be removed later thisevEmitter = DeviceEventEmitter; // Initialize RNGLocation RNGLocation; } { this; } { // Stop listening for Events thisevEmitter; } { return <View style=stylescontainer> <Text style=styleslocation> Lng: thisstatelng Lat: thisstatelat </Text> </View> ; } var styles = StyleSheet; AppRegistry;