react-native-geolocation-service
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,7 +0,11 @@ | ||
import { NativeModules, Platform } from 'react-native'; | ||
import { NativeEventEmitter, NativeModules, Platform } from 'react-native'; | ||
const { RNFusedLocation } = NativeModules; | ||
const LocationEventEmitter = new NativeEventEmitter(RNFusedLocation); | ||
const noop = () => {}; | ||
let subscriptions = []; | ||
let updatesEnabled = false; | ||
// TODO: add static type checker | ||
@@ -14,2 +18,6 @@ const Geolocation = Platform.OS === 'ios' ? global.navigator.geolocation : { | ||
getCurrentPosition: async (success, error = noop, options = {}) => { | ||
if (!success) { | ||
console.error('Must provide a success callback'); | ||
} | ||
// Right now, we're assuming user already granted location permission. | ||
@@ -19,10 +27,75 @@ RNFusedLocation.getCurrentPosition(options, success, error); | ||
watchPosition: (success, error = noop, options = {}) => { // eslint-disable-line no-unused-vars | ||
// eslint-disable-next-line no-console | ||
console.warn('watchPosition is not yet implemented'); | ||
watchPosition: (success, error = null, options = {}) => { | ||
if (!success) { | ||
console.error('Must provide a success callback'); | ||
} | ||
if (!updatesEnabled) { | ||
RNFusedLocation.startObserving(options); | ||
updatesEnabled = true; | ||
} | ||
const watchID = subscriptions.length; | ||
subscriptions.push([ | ||
LocationEventEmitter.addListener('geolocationDidChange', success), | ||
error ? LocationEventEmitter.addListener('geolocationError', error) : null, | ||
]); | ||
return watchID; | ||
}, | ||
clearWatch: (watchID) => { // eslint-disable-line no-unused-vars | ||
// eslint-disable-next-line no-console | ||
console.warn('clearWatch is not yet implemented'); | ||
clearWatch: (watchID) => { | ||
let sub = subscriptions[watchID]; | ||
if (!sub) { | ||
// Silently exit when the watchID is invalid or already cleared | ||
// This is consistent with timers | ||
return; | ||
} | ||
sub[0].remove(); | ||
const sub1 = sub[1]; | ||
if (sub1) { | ||
sub1.remove(); | ||
} | ||
subscriptions[watchID] = undefined; | ||
let noWatchers = true; | ||
for (var ii = 0; ii < subscriptions.length; ii++) { | ||
if (subscriptions[ii]) { | ||
noWatchers = false; // still valid subscriptions | ||
} | ||
} | ||
if (noWatchers) { | ||
Geolocation.stopObserving(); | ||
} | ||
}, | ||
stopObserving: () => { | ||
if (updatesEnabled) { | ||
RNFusedLocation.stopObserving(); | ||
updatesEnabled = false; | ||
for (var ii = 0; ii < subscriptions.length; ii++) { | ||
var sub = subscriptions[ii]; | ||
if (sub) { | ||
console.warn('Called stopObserving with existing subscriptions.'); | ||
sub[0].remove(); | ||
const sub1 = sub[1]; | ||
if (sub1) { | ||
sub1.remove(); | ||
} | ||
} | ||
} | ||
subscriptions = []; | ||
} | ||
} | ||
@@ -29,0 +102,0 @@ }; |
{ | ||
"name": "react-native-geolocation-service", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "React native geolocation service for iOS and android", | ||
@@ -5,0 +5,0 @@ "main": "js/index.js", |
@@ -7,2 +7,4 @@ # react-native-geolocation-service | ||
> NOTE: Location request can still timeout since many android devices have GPS issue in the hardware level or in the system software level. Check the [FAQ](#faq) for more details. | ||
# Installation | ||
@@ -38,3 +40,3 @@ ```bash | ||
} | ||
compile 'com.google.android.gms:play-services-location:11.0.4' | ||
compile 'com.google.android.gms:play-services-location:<insert your play service version here>' | ||
} | ||
@@ -111,1 +113,21 @@ ``` | ||
- [ ] Implement `stopObserving` method for android | ||
# FAQ | ||
1. **Location timeout still happening ?** | ||
Try the following steps: (Taken from [here](https://support.strava.com/hc/en-us/articles/216918967-Troubleshooting-GPS-Issues)) | ||
- 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 | ||
- Xiomi (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 |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
190761
15
75
131