Twinski / react-native-location-change

react native library that uses the iOS Significant-Change Location Service

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

react-native-location-change

React native library for providing low-power, background geographic location changes.

Not supported on Android yet.

On iOS it uses the significant-change location service . It can supply location updates in the background without having to use the Location Updates background mode [view apple docs].

Getting started

Add the dependency (its not on npm yet)

npm install react-native-location-change@https://github.com/npomfret/react-native-location-change.git --save
react-native link react-native-location-change

iOS installation

Standard RN installation instructions for a native module are below, but you also need to modify your info.plist file:

<key>NSLocationWhenInUseUsageDescription</key>
<string>This is needed to get location updates</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>This is needed to get location updates in the background</string>

Usage

import {AppRegistry, StyleSheet, Text, View, NativeModules, NativeEventEmitter} from "react-native";

const _EVENT_EMITTER = new NativeEventEmitter(NativeModules.RNLocationChange);

export default class LocationChangeExample extends Component {
  componentWillMount() {
    this.setState({location: null});

    _EVENT_EMITTER.addListener('significantLocationChange', (data) => {
      console.log("event:", data);
      this.setState({location: data});
    });

    NativeModules.RNLocationChange.start();
  }

  componentWillUnmount() {
    NativeModules.RNLocationChange.stop();
  }

An working example is here.

About

react native library that uses the iOS Significant-Change Location Service


Languages

Language:C# 42.9%Language:Objective-C 29.3%Language:Java 18.7%Language:Ruby 7.6%Language:JavaScript 1.5%