react-native-location-manager-ios

1.0.2 • Public • Published

react-native-location-manager-ios

React Native Location Manager Bridge for iOS

This module is intended for advanced usage, if you only need basic geolocation functionality you will be better with React Native Geolocation module.

Installation

yarn add react-native-location-manager-ios

Automatic linking

react-native link react-native-location-manager-ios

Manual linking

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-location-manager-iosios and add RCTLocationManagerIOS.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRCTLocationManagerIOS.a to your project's Build PhasesLink Binary With Libraries

Usage Description

Add to your Info.plist apropriate *UsageDescription keys with a string value explaining to the user how the app uses location data. Please see official documentation

<key>NSLocationWhenInUseUsageDescription</key>
<string>Some description</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Some description</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Some description</string>

Usage

import LocationManagerIOS from 'react-native-location-manager-ios';

API

Events

Event names are available under LocationManagerIOS.Events object.

const subscription = LocationManagerIOS.addListener(LocationManagerIOS.Events.didUpdateLocations, console.log);
// ...
subscription.remove();

See CLLocationManagerDelegate for in-depth details.

Event Listener Arguments Notes
didUpdateLocations locations: Array<Location>
didFailWithError error: Error
didFinishDeferredUpdatesWithError error: Error
didPauseLocationUpdates
didResumeLocationUpdates
didUpdateHeading heading: Heading
didEnterRegion region: Region
didExitRegion region: Region
didDetermineStateForRegion { region: Region, state: RegionState }
monitoringDidFailForRegion { region: Region, error: Error }
didStartMonitoringForRegion region: Region
didRangeBeaconsInRegion { beacons: Array<Beacon>, region: BeaconRegion }
rangingBeaconsDidFailForRegion { region: BeaconRegion, error: Error }
didVisit visit: Visit
didChangeAuthorizationStatus status: AuthorizationStatus

Enums

LocationManagerIOS.addListener(LocationManagerIOS.Events.didFailWithError, (err) => {
  if (err.code === LocationManagerIOS.Error.LocationUnknown) {
    // ...
  }
});
Enum Keys
AuthorizationStatus NotDetermined, Restricted, Denied, AuthorizedAlways, AuthorizedWhenInUse
LocationAccuracy BestForNavigation, Best, NearestTenMeters, HundredMeters, Kilometer, ThreeKilometers
DistanceFilter None
ActivityType Other, AutomotiveNavigation, Fitness, OtherNavigation
DeviceOrientation Unknown, Portrait, PortraitUpsideDown, LandscapeLeft, LandscapeRight, FaceUp, FaceDown
RegionState Unknown, Inside, Outside
Proximity Unknown, Immediate, Near, Far
Error LocationUnknown, Denied, Network, HeadingFailure, RegionMonitoringDenied, RegionMonitoringFailure, RegionMonitoringSetupDelayed, RegionMonitoringResponseDelayed, GeocodeFoundNoResult, GeocodeFoundPartialResult, GeocodeCanceled, DeferredFailed, DeferredNotUpdatingLocation, DeferredAccuracyTooLow, DeferredDistanceFiltered, DeferredCanceled, RangingUnavailable, RangingFailure

Properties

Property getters return a promise resolved with the property value.

See CLLocationManager for in-depth details.

const monitoredRegions = await LocationManagerIOS.monitoredRegions;
monitoredRegions.forEach(console.log)
 
const distanceFilter = await LocationManagerIOS.distanceFilter;
if (distanceFilter === LocationManagerIOS.DistanceFilter.None) {
  LocationManagerIOS.distanceFilter = 3;
}
 
LocationManagerIOS.desiredAccuracy = LocationManagerIOS.LocationAccuracy.BestForNavigation;
 
LocationManagerIOS.activityType = LocationManagerIOS.ActivityType.AutomotiveNavigation;
Property Type Notes
pausesLocationUpdatesAutomatically bool
allowsBackgroundLocationUpdates bool
showsBackgroundLocationIndicator bool
distanceFilter double
desiredAccuracy double
activityType ActivityType
headingFilter double
headingOrientation DeviceOrientation
maximumRegionMonitoringDistance double readonly
monitoredRegions Array<CircularRegion> readonly
rangedRegions Array<BeaconRegion> readonly
location Location readonly
heading Heading readonly

Methods

Non void methods return a promise which will resolve to the according type.

See CLLocationManager for in-depth details.

Method Arguments Return Notes
addListener event: string, listener: function {remove: function} custom
authorizationStatus AuthorizationStatus
locationServicesEnabled bool
deferredLocationUpdatesAvailable bool
significantLocationChangeMonitoringAvailable bool
headingAvailable bool
isRangingAvailable bool
requestWhenInUseAuthorization void
requestAlwaysAuthorization void
startUpdatingLocation void
stopUpdatingLocation void
requestLocation void
startMonitoringSignificantLocationChanges void
stopMonitoringSignificantLocationChanges void
startUpdatingHeading void
stopUpdatingHeading void
dismissHeadingCalibrationDisplay void
startMonitoringForRegion identifier: string, latitude: double, longitude: double, radius: double, notifyOnEntry: bool, notifyOnExit: bool void
stopMonitoringForRegion identifier: string void
stopMonitoringForAllRegions void custom
startRangingBeaconsInRegion identifier: string, proximityUUID: string, major: int, minor: int, notifyOnEntry: bool, notifyOnExit: bool void
stopRangingBeaconsInRegion identifier: string void
stopRangingBeaconsInAllRegions void custom
requestStateForRegion identifier: string void
startMonitoringVisits void
stopMonitoringVisits void
allowDeferredLocationUpdatesUntilTraveled distance: double, timeout: double void
disallowDeferredLocationUpdates void

Types

type Error {
  code: int,
  domain: string,
}
type Location {
  altitude: double,
  horizontalAccuracy: double,
  verticalAccuracy: double,
  speed: double,
  course: double,
  timestamp: double, // precision is to the millisecond
  coordinate: Coordinate,
}
type Coordinate {
  latitude: double,
  longitude: double,
}
type Region {
  identifier: string,
  notifyOnEntry: bool,
  notifyOnExit: bool,
}
type CircularRegion {
  identifier: string,
  radius: double,
  center: Coordinate,
  notifyOnEntry: bool,
  notifyOnExit: bool,
}
type BeaconRegion {
  identifier: string,
  proximityUUID: string,
  major: int,
  minor: int,
  notifyOnEntry: bool,
  notifyOnExit: bool,
}
type Beacon {
  proximityUUID: string,
  major: int,
  minor: int,
  proximity: LocationManagerIOS.Proximity,
  accuracy: double,
  rssi: long,
}
type Visit {
  horizontalAccuracy: double,
  arrivalDate: double, // precision is to the millisecond
  departureDate: double, // precision is to the millisecond
  coordinate: Coordinate,
}
type Heading {
  magneticHeading: double,
  trueHeading: double,
  headingAccuracy: double,
  timestamp: double, // precision is to the millisecond
  x: double,
  y: double,
  z: double,
}

Custom

LocationManagerIOS.stopMonitoringForAllRegions()

Native implementation for:

const monitoredRegions = await LocationManagerIOS.monitoredRegions;
monitoredRegions.map(r => r.identifier)
  .forEach(LocationManagerIOS.stopMonitoringForRegion);

LocationManagerIOS.stopRangingBeaconsInAllRegions()

Native implementation for:

const rangedRegions = await LocationManagerIOS.rangedRegions;
rangedRegions.map(r => r.identifier)
  .forEach(LocationManagerIOS.stopRangingBeaconsInRegion);

/react-native-location-manager-ios/

    Package Sidebar

    Install

    npm i react-native-location-manager-ios

    Weekly Downloads

    1

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    63.4 kB

    Total Files

    7

    Last publish

    Collaborators

    • djhr