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.
yarn add react-native-location-manager-ios
react-native link react-native-location-manager-ios
- In XCode, in the project navigator, right click
Libraries
âžśAdd Files to [your project's name]
- Go to
node_modules
âžśreact-native-location-manager-ios
âžśios
and addRCTLocationManagerIOS.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRCTLocationManagerIOS.a
to your project'sBuild Phases
âžśLink Binary With Libraries
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>
import LocationManagerIOS from 'react-native-location-manager-ios';
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 |
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 |
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 |
Non void
methods return a promise which will resolve to the according type.
See CLLocationManager
for in-depth details.
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,
}
Native implementation for:
const monitoredRegions = await LocationManagerIOS.monitoredRegions;
monitoredRegions.map(r => r.identifier)
.forEach(LocationManagerIOS.stopMonitoringForRegion);
Native implementation for:
const rangedRegions = await LocationManagerIOS.rangedRegions;
rangedRegions.map(r => r.identifier)
.forEach(LocationManagerIOS.stopRangingBeaconsInRegion);