Git Product home page Git Product logo

react-native-location-change's Introduction

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:

iOS 11 and higher: NSLocationAlwaysAndWhenInUseUsageDescription This is needed to get location updates NSLocationAlwaysUsageDescription This is needed to get location updates in the background

Prior to iOS 11: NSLocationAlwaysAndWhenInUseUsageDescription This is needed to get location updates NSLocationAlwaysUsageDescription This is needed to get location updates in the background

If you'd like background updates, you may also need to add the following UI background modes to youy info.plist file:

<key>UIBackgroundModes</key>
<array>
	<string>fetch</string>
	<string>location</string>
</array>

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.

react-native-location-change's People

Contributors

npomfret avatar joem-rp avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.