All Projects → Agontuk → React Native Geolocation Service

Agontuk / React Native Geolocation Service

Licence: mit
React native geolocation service for iOS and android

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to React Native Geolocation Service

exploring-my-neighborhood
track all your moves and visualize them!
Stars: ✭ 16 (-98.29%)
Mutual labels:  location, geolocation
Flutter Geolocator
Android and iOS Geolocation plugin for Flutter
Stars: ✭ 759 (-18.74%)
Mutual labels:  location, geolocation
pikaz-location
定位插件(限中国)
Stars: ✭ 78 (-91.65%)
Mutual labels:  location, geolocation
Geolocation
Flutter geolocation plugin for Android and iOS.
Stars: ✭ 205 (-78.05%)
Mutual labels:  location, geolocation
React Native Baidumap Sdk
React Native BaiduMap SDK for Android + iOS
Stars: ✭ 309 (-66.92%)
Mutual labels:  location, geolocation
Use Position
🌍 React hook usePosition() for fetching and following a browser geolocation
Stars: ✭ 230 (-75.37%)
Mutual labels:  location, geolocation
discourse-locations
Tools for handling locations in Discourse
Stars: ✭ 31 (-96.68%)
Mutual labels:  location, geolocation
Coregpx
A library for parsing and creation of GPX location files. Purely Swift.
Stars: ✭ 132 (-85.87%)
Mutual labels:  location, geolocation
React Native Amap Geolocation
React Native geolocation module for Android + iOS
Stars: ✭ 289 (-69.06%)
Mutual labels:  location, geolocation
kirby-locator
A simple map & geolocation field, built on top of open-source services and Mapbox. Kirby 3 only.
Stars: ✭ 83 (-91.11%)
Mutual labels:  location, geolocation
React Native Google Place Picker
React Native Wrapper of Google Place Picker for iOS + Android.
Stars: ✭ 180 (-80.73%)
Mutual labels:  location, native
Leku
🌍 Map location picker component for Android. Based on Google Maps. An alternative to Google Place Picker.
Stars: ✭ 612 (-34.48%)
Mutual labels:  location, geolocation
React Native Android Location Services Dialog Box
React Native Android Location Services Dialog Box
Stars: ✭ 175 (-81.26%)
Mutual labels:  location, geolocation
Timezonefinder
fast python package for finding the timezone of any point on earth (coordinates) offline
Stars: ✭ 242 (-74.09%)
Mutual labels:  location, geolocation
Track Ip
Advanced Ip Tracker Tool
Stars: ✭ 150 (-83.94%)
Mutual labels:  location, geolocation
orange3-geo
🍊 🌍 Orange add-on for dealing with geography and geo-location
Stars: ✭ 22 (-97.64%)
Mutual labels:  location, geolocation
P5.geolocation
a geolocation and geofencing library for p5.js
Stars: ✭ 75 (-91.97%)
Mutual labels:  location, geolocation
Geo Location
Web component element for the Geolocation API
Stars: ✭ 86 (-90.79%)
Mutual labels:  location, geolocation
simple-location
Adds Basic Location Support to Wordpress
Stars: ✭ 26 (-97.22%)
Mutual labels:  location, geolocation
Googleapi
C# .NET Core Google Api (Maps, Places, Roads, Search, Translate). Supports all endpoints and requests / responses.
Stars: ✭ 346 (-62.96%)
Mutual labels:  location, geolocation

react-native-geolocation-service

React native geolocation service for iOS and android.

Why ?

This library is created in an attempt to fix the location timeout issue on android with the react-native's current implementation of Geolocation API. This library tries to solve the issue by using Google Play Service's new FusedLocationProviderClient API, which Google strongly recommends over android's default framework location API. It automatically decides which provider to use based on your request configuration and also prompts you to change the location mode if it doesn't satisfy your current request configuration.

NOTE: Location request can still timeout since many android devices have GPS issue in the hardware/system level. Check the FAQ for more details.

Installation

yarn

yarn add react-native-geolocation-service

npm

npm install react-native-geolocation-service

Compatibility

RN Version Package Version
>=0.60 >=3.0.0
<0.60 2.0.0
<0.57 1.1.0

Setup

Usage

Since this library was meant to be a drop-in replacement for the RN's Geolocation API, the usage is pretty straight forward, with some extra error cases to handle.

One thing to note, for android this library assumes that location permission is already granted by the user, so you have to use PermissionsAndroid to request for permission before making the location request.

...
import Geolocation from 'react-native-geolocation-service';
...

componentDidMount() {
  if (hasLocationPermission) {
    Geolocation.getCurrentPosition(
        (position) => {
          console.log(position);
        },
        (error) => {
          // See error code charts below.
          console.log(error.code, error.message);
        },
        { enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 }
    );
  }
}

API

async requestAuthorization(authorizationLevel) (iOS only)

Request location permission based on the authorizationLevel parameter. Can be either "whenInUse" or "always". You have to configure the plist keys during setup.

When promise resolves, returns the status of the authorization.

  • disabled - Location service is disabled
  • granted - Permission granted
  • denied - Permission denied
  • restricted - Permission restricted

getCurrentPosition(successCallback, ?errorCallback, ?options)

  • successCallback: Invoked with latest location info.

  • errorCallback: Invoked whenever an error is encountered.

  • options:

    Name Type Default Description
    timeout ms INFINITY Request timeout
    maximumAge ms INFINITY How long previous location will be cached
    accuracy object -- {
       android: Link,
       ios: Link
    }

    If not provided or provided with invalid value, falls back to use enableHighAccuracy
    enableHighAccuracy bool false Use high accuracy mode
    distanceFilter m 0 Minimum displacement in meters
    showLocationDialog bool true Whether to ask to enable location in Android (android only)
    forceRequestLocation bool false Force request location even after denying improve accuracy dialog (android only)

watchPosition(successCallback, ?errorCallback, ?options)

  • successCallback: Invoked with latest location info.

  • errorCallback: Invoked whenever an error is encountered.

  • options:

    Name Type Default Description
    accuracy object -- {
       android: Link,
       ios: Link
    }

    If not provided or provided with invalid value, falls back to use enableHighAccuracy
    enableHighAccuracy bool false Use high accuracy mode
    distanceFilter m 100 Minimum displacement between location updates in meters
    interval ms 10000 Interval for active location updates (android only)
    fastestInterval ms 5000 Fastest rate at which your application will receive location updates, which might be faster than interval in some situations (for example, if other applications are triggering location updates) (android only)
    showLocationDialog bool true whether to ask to enable location in Android (android only)
    forceRequestLocation bool false Force request location even after denying improve accuracy dialog (android only)
    useSignificantChanges bool false Uses the battery-efficient native significant changes APIs to return locations. Locations will only be returned when the device detects a significant distance has been breached (iOS only)
    showsBackgroundLocationIndicator bool false This setting enables a blue bar or a blue pill in the status bar on iOS. When the app moves to the background, the system uses this property to determine whether to change the status bar appearance to indicate that location services are in use. Users can tap the indicator to return to your app. (iOS only)

clearWatch(watchId)

  • watchId (id returned by watchPosition)

stopObserving()

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

Error Codes

Name Code Description
PERMISSION_DENIED 1 Location permission is not granted
POSITION_UNAVAILABLE 2 Location provider not available
TIMEOUT 3 Location request timed out
PLAY_SERVICE_NOT_AVAILABLE 4 Google play service is not installed or has an older version (android only)
SETTINGS_NOT_SATISFIED 5 Location service is not enabled or location mode is not appropriate for the current request (android only)
INTERNAL_ERROR -1 Library crashed for some reason or the getCurrentActivity() returned null (android only)

FAQ

  1. Location timeout still happening ?

    Try the following steps: (Taken from here)

    • Turn phone off/on
    • Turn GPS off/on
    • Disable any battery saver settings, including Power Saving Mode, Battery Management or any third party apps
    • Perform an "AGPS reset": Install the App GPS Status & Toolbox, then in that app, go to Menu > Tools > Manage A-GPS State > Reset

    Adjusting battery saver settings on different devices:

    • HTC: Access your phone settings > battery > power saving mode > battery optimization > select your app > don't optimize > save
    • Huawei: Turn Energy Settings to Normal and add your app to "Protected Apps"
    • LG If you're running Android 6 or higher: Settings > battery & power saving > battery usage > ignore optimizations > turn ON for your app
    • Motorola If you're running Android 6 or higher: Battery > select the menu in the upper right-hand corner > battery optimization > not optimized > all apps > select your app > don't optimize
    • OnePlus (using OxygenOS Settings): Battery > battery optimization > switch to 'all apps' > select your app > don't optimize
    • Samsung: Access battery settings > app power saving > details > your app > disabled
    • Sony If you're running Android 6 or higher: Battery > from the menu in the upper right-hand corner > battery optimization > apps > your app
    • Xiaomi (MIUI OS) If you're running Android 6 or higher: Access your phone settings > additional settings > battery and performance > manage battery usage > apps > your app
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].