Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-location

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-location

Native GPS location support for React Native.

  • 0.13.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.6K
decreased by-0.46%
Maintainers
1
Weekly downloads
 
Created
Source

react-native-location

Native GPS location support for React Native.

Installation

Install using npm with npm install --save react-native-location

You then need to add the Objective C part to your XCode project. Drag RNLocation.xcodeproj from the node_modules/react-native-location folder into your XCode project. Click on the your project in XCode, goto Build Phases then Link Binary With Libraries and add libRNLocation.a and CoreLocation.framework.

NOTE: Make sure you don't have the RNLocation project open separately in XCode otherwise it won't work.

Usage

var React = require('react-native');
var {DeviceEventEmitter} = React;

var Location = require('react-native-location');

Location.requestAlwaysAuthorization();
Location.startUpdatingLocation();
Location.setDistanceFilter(5.0);

var subscription = DeviceEventEmitter.addListener(
    'locationUpdated',
    (location) => {
        // do something with the location
    }
);

It is recommended to set NSWhenInUseUsageDescription in your Info.plist file.

Background mode

For background mode to work, a few things need to be configured:

  1. In the Xcode project, go to Capabilities, switch on "Background Modes" and check "Location updates".
  2. Using requestAlwaysAuthorization in place of requestWhenInUseAuthorization:
Location.requestAlwaysAuthorization();
  1. Set NSLocationAlwaysUsageDescription in your Info.plist file.

Methods

To access the methods, you need import the react-native-location module. This is done through var Beacons = require('react-native-location').

Location.requestWhenInUseAuthorization

Location.requestWhenInUseAuthorization();

This method should be called before anything else. It requests location updates while the application is open. If the application is in the background, you will not get location updates. Either this method or Location.requestAlwaysAuthorization (but not both) needs to be called to receive updates.

Location.requestAlwaysAuthorization

Location.requestAlwaysAuthorization();

This method should be called before anything else is called. It requests location updates while the application is open or in the background. Either this method or Location.requestWhenInUseAuthorization (but not both) needs to be called to receive updates.

Location.getAuthorizationStatus

Location.getAuthorizationStatus(function(authorization) {
  // authorization is a string which is either "authorizedAlways",
  // "authorizedWhenInUse", "denied", "notDetermined" or "restricted"
});

This methods gets the current authorization status. While this methods provides a callback, it is not executed asynchronously. The values authorizedAlways and authorizedWhenInUse correspond to the methods requestWhenInUseAuthorization and requestAlwaysAuthorization respectively.

Location.setDesiredAccuracy

Location.setDesiredAccuracy(distanceInMeters);

Set the desired accuracy of location updates in meters. Determines the method used to obtain location updates. Low values will trigger using GPS.

Location.setDistanceFilter

Location.setDistanceFilter(distanceInMeters);

Set the desired minimum distance between location updates in meters.

Location.startMonitoringSignificantLocationChanges

Location.startMonitoringSignificantLocationChanges();

Location.startUpdatingLocation

Location.startUpdatingLocation();
var subscription = DeviceEventEmitter.addListener(
    'locationUpdated',
    (location) => {
        // do something with the location
    }
);

Start signifcant location updates (typically using network sources like Wifi/Cellular and with a minimum time gap of 5 minutes). Your application will be called back with location updates via the DeviceEventEmitter event 'locationUpdated'.

Location.startUpdatingLocation

Location.startUpdatingLocation();
var subscription = DeviceEventEmitter.addListener(
    'locationUpdated',
    (location) => {
        // do something with the location
    }
);

Start location updates. Your application will be called back with location updates that meet any mininum distance requirements that you specify via the DeviceEventEmitter event 'locationUpdated'.

Location.stopUpdatingLocation

Location.stopUpdatingLocation();

Stop receiving location events.

Location.stopMonitoringSignificantLocationChanges

Location.stopMonitoringSignificantLocationChanges();

Stop receiving sigificant location change events.

Events

To listen to events we need to call DeviceEventEmitter.addListener (var {DeviceEventEmitter} = require('react-native')) where the first parameter is the event we want to listen to and the second is a callback function that will be called once the event is triggered.

locationUpdated

Received when a location update has been sensed by the system. The event delivers one parameter, location, that is an object with location, elevation, and accuracy data.

License

MIT, for more information see LICENSE

Keywords

FAQs

Package last updated on 26 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc