1.0.2 • Published 6 years ago

react-native-location-manager-ios v1.0.2

Weekly downloads
12
License
MIT
Repository
github
Last release
6 years ago

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.

EventListener ArgumentsNotes
didUpdateLocationslocations: Array<Location>
didFailWithErrorerror: Error
didFinishDeferredUpdatesWithErrorerror: Error
didPauseLocationUpdates
didResumeLocationUpdates
didUpdateHeadingheading: Heading
didEnterRegionregion: Region
didExitRegionregion: Region
didDetermineStateForRegion{ region: Region, state: RegionState }
monitoringDidFailForRegion{ region: Region, error: Error }
didStartMonitoringForRegionregion: Region
didRangeBeaconsInRegion{ beacons: Array<Beacon>, region: BeaconRegion }
rangingBeaconsDidFailForRegion{ region: BeaconRegion, error: Error }
didVisitvisit: Visit
didChangeAuthorizationStatusstatus: AuthorizationStatus

Enums

LocationManagerIOS.addListener(LocationManagerIOS.Events.didFailWithError, (err) => {
  if (err.code === LocationManagerIOS.Error.LocationUnknown) {
    // ...
  }
});
EnumKeys
AuthorizationStatusNotDetermined, Restricted, Denied, AuthorizedAlways, AuthorizedWhenInUse
LocationAccuracyBestForNavigation, Best, NearestTenMeters, HundredMeters, Kilometer, ThreeKilometers
DistanceFilterNone
ActivityTypeOther, AutomotiveNavigation, Fitness, OtherNavigation
DeviceOrientationUnknown, Portrait, PortraitUpsideDown, LandscapeLeft, LandscapeRight, FaceUp, FaceDown
RegionStateUnknown, Inside, Outside
ProximityUnknown, Immediate, Near, Far
ErrorLocationUnknown, 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;
PropertyTypeNotes
pausesLocationUpdatesAutomaticallybool
allowsBackgroundLocationUpdatesbool
showsBackgroundLocationIndicatorbool
distanceFilterdouble
desiredAccuracydouble
activityTypeActivityType
headingFilterdouble
headingOrientationDeviceOrientation
maximumRegionMonitoringDistancedoublereadonly
monitoredRegionsArray<CircularRegion>readonly
rangedRegionsArray<BeaconRegion>readonly
locationLocationreadonly
headingHeadingreadonly

Methods

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

See CLLocationManager for in-depth details.

MethodArgumentsReturnNotes
addListenerevent: string, listener: function{remove: function}custom
authorizationStatusAuthorizationStatus
locationServicesEnabledbool
deferredLocationUpdatesAvailablebool
significantLocationChangeMonitoringAvailablebool
headingAvailablebool
isRangingAvailablebool
requestWhenInUseAuthorizationvoid
requestAlwaysAuthorizationvoid
startUpdatingLocationvoid
stopUpdatingLocationvoid
requestLocationvoid
startMonitoringSignificantLocationChangesvoid
stopMonitoringSignificantLocationChangesvoid
startUpdatingHeadingvoid
stopUpdatingHeadingvoid
dismissHeadingCalibrationDisplayvoid
startMonitoringForRegionidentifier: string, latitude: double, longitude: double, radius: double, notifyOnEntry: bool, notifyOnExit: boolvoid
stopMonitoringForRegionidentifier: stringvoid
stopMonitoringForAllRegionsvoidcustom
startRangingBeaconsInRegionidentifier: string, proximityUUID: string, major: int, minor: int, notifyOnEntry: bool, notifyOnExit: boolvoid
stopRangingBeaconsInRegionidentifier: stringvoid
stopRangingBeaconsInAllRegionsvoidcustom
requestStateForRegionidentifier: stringvoid
startMonitoringVisitsvoid
stopMonitoringVisitsvoid
allowDeferredLocationUpdatesUntilTraveleddistance: double, timeout: doublevoid
disallowDeferredLocationUpdatesvoid

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);