rnl

react-native-location-permission

A react Native module to enable location based services on Android and IOS

Showing:

Popularity

Downloads/wk

29

GitHub Stars

1

Maintenance

Last Commit

6mos ago

Contributors

3

Package

Dependencies

0

License

MIT

Type Definitions

Tree-Shakeable

No?

Reviews

Average Rating

4.0/52
Read All Reviews

Top Feedback

1Easy to Use

Readme

React Native Location Permission

A react Native module to enable location based services on Android and IOS.

Requirements

  • react-native >= 0.38.0
  • android buildToolsVersion 26.0.1
  • gradle build tools 2.3.3

Installation Android

  1. npm install react-native-location-permission

  2. add the following 2 lines to your /android/settings.gradle file

    include ':react-native-location-permission'
    project(':react-native-location-permission').projectDir = new File(settingsDir, '../node_modules/react-native-location-permission/android')
    
  3. add the following line to your /android/app/build.gradle file

    compile project(':react-native-location-permission')
    
  4. add the "LocationSwitchPackage" import into your MainApplication.java file:

    import org.amen.reactnative.locationswitch.LocationSwitchPackage;
    
  5. add the "LocationSwitchPackage" into your MainApplication.java file (getPackages method):

     @Override
     protected List<ReactPackage> getPackages() {
       return Arrays.<ReactPackage>asList(
           new MainReactPackage(),
           ... // your other react native packages
           new LocationSwitchPackage()
       );
     }
    
    
  6. add the "LocationSwitch" import into your MainActivity.java file:

    import org.amen.reactnative.locationswitch.LocationSwitch;
    
  7. add the following code into your MainActivity.java file:

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        LocationSwitch.getInstance().onActivityResult(requestCode, resultCode);
    }
    

Installation IOS

Using Pods :

  1. add the following into your podfile :
    pod 'ReactNativeLocationSwitch', :path => '../node_modules/react-native-location-permission/ios'
    

Using xcode :

  1. Open the project in xCode, left click on the Libraries folder -> Add files to ... and select

    ./node_modules/react-native-location-permission/ios/RNReactNativeLocationSwitch.xcodeproj
    
  2. Open the project -> Build Phases -> Link Binary With Libraries and select libRNReactNativeLocationSwitch.a

React Native Interface

LocationSwitch.enableLocationService(
    interval,
    requestHighAccuracy,
    successCallback,
    errorCallback
);
LocationSwitch.isLocationEnabled(
    successCallback,
    errorCallback
);
OptionDefaultInfo
interval1000Update interval in ms (ignored on IOS)
requestHighAccuracyfalseIf true, highest accuracy is requested. If false, "block" level accuracy is requested (ignored on IOS)
successCallbacknullIs called when the user allows access to the location services or when the location services are already enabled
errorCallbacknullIs called when the user denies access to the location services

Usage

import React, { Component } from 'react';
import { AppRegistry, Text, View, TouchableOpacity, StyleSheet, Alert } from 'react-native';
import LocationSwitch from 'react-native-location-permission';

const style = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  button: {
    padding: 20,
  },
  text: {
    fontSize: 20,
  },
  textSuccess: {
    fontSize: 20,
    color: 'green',
  },
});

export default class LocationSwitchApp extends Component {

  constructor(props) {
    super(props);

    this.state = { locationEnabled: false };
    this.onEnableLocationPress = this.onEnableLocationPress.bind(this);
  }

  componentDidMount() {
    LocationSwitch.isLocationEnabled(
      () => {
        Alert.alert('Location is enabled');
        this.setState({ locationEnabled: true });
      },
      () => { Alert.alert('Location is disabled'); },
    );
  }

  onEnableLocationPress() {
    LocationSwitch.enableLocationService(1000, true,
      () => { this.setState({ locationEnabled: true }); },
      () => { this.setState({ locationEnabled: false }); },
    );
  }

  renderLocationStatus() {
    if (this.state.locationEnabled) {
      return <Text style={style.textSuccess} >Location enabled</Text>;
    }
    return <Text style={style.text}>Location disabled</Text>;
  }

  render() {
    return (
      <View style={style.container}>
        <TouchableOpacity style={style.button} onPress={this.onEnableLocationPress}>
          <Text style={style.text}>Enable location service</Text>
        </TouchableOpacity>
        {this.renderLocationStatus()}
      </View>
    );
  }
}

AppRegistry.registerComponent('reactClientSandbox', () => LocationSwitchApp);

Rate & Review

Great Documentation0
Easy to Use1
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

react-native-permissionsAn unified permissions API for React Native on iOS and Android
User Rating
4.9/ 5
8
Top Feedback
6Easy to Use
4Great Documentation
4Performant
GitHub Stars
3K
Weekly Downloads
167K
expo-permissionsAn open-source platform for making universal native apps with React. Expo runs on Android, iOS, and the web.
User Rating
4.7/ 5
19
Top Feedback
18Great Documentation
16Easy to Use
11Performant
GitHub Stars
15K
Weekly Downloads
82K
expo-permissions-interfaceAn open-source platform for making universal native apps with React. Expo runs on Android, iOS, and the web.
User Rating
5.0/ 5
1
Top Feedback
1Easy to Use
GitHub Stars
15K
Weekly Downloads
211
rna
react-native-android-permissionsReact Native Android Permissions experimental module - Android M (6.0) permissions like to your React Native application
User Rating
5.0/ 5
1
Top Feedback
1Highly Customizable
GitHub Stars
122
Weekly Downloads
14
rne
react-native-easy-permissionsReact Native: Native Easy Permissions
User Rating
4.0/ 5
1
Top Feedback
1Easy to Use
GitHub Stars
31
Weekly Downloads
1

Tutorials

No tutorials found
Add a tutorial