New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-native-cross-geolocation

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-cross-geolocation

React Native Geolocation complatible module that uses the new Google Location API in Android devices.

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

react-native-cross-geolocation

npm License

React Native Geolocation complatible module that uses the new Google Location API in Android devices.

This module is for React Native 0.50.x using the Google Gradle plugin 3.1.2 or later.

Setup

$ yarn add react-native-cross-geolocation
$ react-native link react-native-cross-geolocation

JavaScript import:

import Geolocation from 'react-native-cross-geolocation'

Configuration and Permissions

This section only applies to projects made with react-native init or to those made with Create React Native App which have since ejected. For more information about ejecting, please see the guide on the Create React Native App repository.

iOS

You need to include the NSLocationWhenInUseUsageDescription key in Info.plist to enable geolocation when using the app. Geolocation is enabled by default when you create a project with react-native init.

In order to enable geolocation in the background, you need to include the 'NSLocationAlwaysUsageDescription' key in Info.plist and add location as a background mode in the 'Capabilities' tab in Xcode.

Android

To request access to location, you need to add the following line to your app's AndroidManifest.xml:

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Android API >= 18 Positions will also contain a mocked boolean to indicate if position was created from a mock provider. Android API >= 23 Permissions are handled automatically.

Methods

Reference

Methods

setRNConfiguration()
Geolocation.setRNConfiguration(config);

Sets configuration options that will be used in all location requests.

Parameters:

NAMETYPEREQUIREDDESCRIPTION
configobjectYesSee below.

Supported options (optionals):

  • skipPermissionRequests (boolean, iOS-only) - Defaults to false. If true, you must request permissions before using Geolocation APIs.
  • lowAccuracyMode (number, Android-only) - Defaults to LowAccuracyMode.BALANCED.
  • fastestInterval (number, Android-only) - Defaults to 10000 (10 secs).
  • updateInterval (number, Android-only) - Defaults to 5000 (5 secs).
requestAuthorization()
Geolocation.requestAuthorization();

Request suitable Location permission based on the key configured on pList. If NSLocationAlwaysUsageDescription is set, it will request Always authorization, although if NSLocationWhenInUseUsageDescription is set, it will request InUse authorization.

getCurrentPosition()
Geolocation.getCurrentPosition(geo_success, [geo_error], [geo_options]);

Invokes the success callback once with the latest location info.

Parameters:

NAMETYPEREQUIREDDESCRIPTION
geo_successfunctionYesInvoked with latest location info.
geo_errorfunctionNoInvoked whenever an error is encountered.
geo_optionsobjectNoSee below.

Supported options:

  • timeout (ms) - Defaults to MAX_VALUE
  • maximumAge (ms) - Defaults to INFINITY.
  • enableHighAccuracy (bool) - On Android, if the location is cached this can return almost immediately, or it will request an update which might take a while.
watchPosition()
Geolocation.watchPosition(success, [error], [options]);

Invokes the success callback whenever the location changes. Returns a watchId (number).

Parameters:

NAMETYPEREQUIREDDESCRIPTION
successfunctionYesInvoked whenever the location changes.
errorfunctionNoInvoked whenever an error is encountered.
optionsobjectNoSee below.

Supported options:

  • timeout (ms) - Defaults to MAX_VALUE.
  • maximumAge (ms) - Defaults to INFINITY.
  • enableHighAccuracy (bool) - Defaults to false.
  • distanceFilter (m)
  • useSignificantChanges (bool) (unused in Android).
clearWatch()
Geolocation.clearWatch(watchID);

Parameters:

NAMETYPEREQUIREDDESCRIPTION
watchIDnumberYesId as returned by watchPosition().
stopObserving()
Geolocation.stopObserving();

Stops observing for device location changes. In addition, it removes all listeners previously registered.

Notice that this method has only effect if the geolocation.watchPosition(successCallback, errorCallback) method was previously invoked.

TODO

  • Enhanced docs
  • Tests

Keywords

FAQs

Package last updated on 18 Jun 2018

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