8000 GitHub - mobileemotion/react-native-background-geolocation: Background and foreground geolocation plugin for React Native. Tracks user when app is running in background.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Background and foreground geolocation plugin for React Native. Tracks user when app is running in background.

License

Notifications You must be signed in to change notification settings

mobileemotion/react-native-background-geolocation

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-mauron85-background-geolocation

Donation

Please support my work and support continuous development by your donation.

Donate

Description

Special React Native fork of cordova-plugin-mauron85-background-geolocation.

Example Apps

Repository react-native-background-geolocation-example is hosting example app for both iOS and Android platform.

Quick example

import React, { Component } from 'react';
import BackgroundGeolocation from 'react-native-mauron85-background-geolocation';

class BgTracking extends Component {
  componentWillMount() {
    BackgroundGeolocation.configure({
      desiredAccuracy: 10,
      stationaryRadius: 50,
      distanceFilter: 50,
      locationTimeout: 30,
      notificationTitle: 'Background tracking'
89D9
,
      notificationText: 'enabled',
      debug: true,
      startOnBoot: false,
      stopOnTerminate: false,
      locationProvider: 1, // 0 => ANDROID_DISTANCE_FILTER_PROVIDER | 1 => ANDROID_ACTIVITY_PROVIDER
      interval: 10000,
      fastestInterval: 5000,
      activitiesInterval: 10000,
      stopOnStillActivity: false,
      url: 'http://192.168.81.15:3000/location',
      httpHeaders: {
        'X-FOO': 'bar'
      }
    });
    
    BackgroundGeolocation.on('location', (location) => {
      //handle your locations here
      Actions.sendLocation(location);
    }); 

    BackgroundGeolocation.on('error', (error) => {
      console.log('[ERROR] BackgroundGeolocation error:', error);
    });

    BackgroundGeolocation.start(() => {
      console.log('[DEBUG] BackgroundGeolocation started successfully');    
    });
  }
}

export default BgTracking;

Instalation

Add package to your project

npm install react-native-mauron85-background-geolocation --save

Android setup

In android/settings.gradle

...
include ':react-native-mauron85-background-geolocation', ':app'
project(':react-native-mauron85-background-geolocation').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-mauron85-background-geolocation/android')
...

In android/app/build.gradle

dependencies {
    ...
    compile project(':react-native-mauron85-background-geolocation')
    ...
}

Register module (in MainActivity.java)

import com.marianhello.react.BackgroundGeolocationPackage;  // <--- Import Package

public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
  ...
  /**
   * A list of packages used by the app. If the app uses additional views
   * or modules besides the default ones, add more packages here.
   */
  @Override
  protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new BackgroundGeolocationPackage() // <---- Add the Package
      );
  }
  ...
}

iOS setup

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. add ./node_modules/react-native-mauron85-background-geolocation/ios/RCTBackgroundGeolocation.xcodeproj
  3. In the XCode project navigator, select your project, select the Build Phases tab and in the Link Binary With Libraries section add libRCTBackgroundGeolocation.a
  4. add UIBackgroundModes location to Info.plist
  5. add NSLocationAlwaysUsageDescription App requires background tracking to Info.plist

About

Background and foreground geolocation plugin for React Native. Tracks user when app is running in background.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 64.2%
  • Objective-C 19.8%
  • JavaScript 15.6%
  • Shell 0.4%
0