Watch location of user on iOS seems to not be using GPS. The accuracy never goes below 65 and the speed is negative, which seems like that the GPS is not kicking in. It works just fine for Android. Also, navigator.geolocation works just fine in the browser with accurate speed and accuracy. (https://codepen.io/himanshu/full/bqoEQN/)
Reproduced in Expo. (https://sketch.expo.io/S15lAdDsx)
React native needs to respect the enableHighAccuracy and distanceFilter flags and return the proper accurate location.
I've the same problem. How to fix it?
Hi,
same issue, get negative value for speed and weird coordinates/timestamp. very critical to me since I started implementing an app which works fine on android and am porting it to ios now (to deliver in may).
any workaround ? any visibility on a fix ? are we supposed to vote this up on some other platform than github?
"react": "15.4.2",
"react-native": "0.42.3",
platform ios 10.3
tested on ipad 2 (target is iphone but this is all I have at the moment)
thx,
Jeremie
hi @himanshu266 @mbokowy did you guys find a workaround?
@jcharlet Yes, I changed this default value to 0. This works for me because I wanted constant updates. You may have a different case.
https://github.com/facebook/react-native/blob/master/Libraries/Geolocation/RCTLocationObserver.m#L28
@himanshu266 Let me know if I understand you correctly - you hardcoded the RCT_DEFAULT_LOCATION_ACCURACY value to 0.0 inside the RCTLocationObserver.m file? And this prevents iOS from just using the network location?
As the name describes, it's the location accuracy. When you set it to 0, every single time the phone moves, even a bit, new location gets updated. Otherwise it was set to 100 meters, which is pretty big gap.
@himanshu266 True, though that should be possible to do with the distanceFilter prop too, right? For me the issue isn't that it doesn't update often, it's just that it's very inaccurate because it doesn't seem to use the actual GPS (not an issue on Android).
Yes, the distanceFilter should work, but if you look lower down in the file you will notice they are doing the math and resetting it back to the default. Hence my fast easy fix for my application was to set the default to 0.
I'll try that then, thanks for explaining.
sorry to ask such a trivial question (am new to the node/xcode world): how do you patch a file from a node_modules package ?
@himanshu266 Do I have to replace the value directly in that ./myApp/node_modules/react-native/Libraries/Geolocation/RCTLocationObserver.m (while node_modules is ignored by git and overridden at any npm install). Is there a cleaner way so that it's not in node_modules and in my git codebase?
I cannot monkey patch since it's not a js file..
@jcharlet I can confirm that changing the value in the library under node_modules does work!
I think the only real solution is to actually fix the underlying bug in react-native itself 馃檪
thx @plougsgaard !
Any solution towards improving the accuracy/speed/heading that returns from the geolocation api?
@himanshu266 thanks for the fix.
But I would rather set RCT_DEFAULT_LOCATION_ACCURACY to kCLLocationAccuracyBest instead of 0.0 because the value of these "accuracy constants" are not documented by Apple and may change (if kCLLocationAccuracyBest is 0.0, what is
kCLLocationAccuracyBestForNavigation?)
Back to the root cause, I don't get why this desiredAccuracy is changed after we succeed or fail to get a position?
See:
And why compare the difference ABS(_locationManager.desiredAccuracy - RCT_DEFAULT_LOCATION_ACCURACY) to 0.000001?? (again, we have no idea how Apple implemented their accuracy constants)
Wow thanks this was driving my nuts... Had tried all kinds of combinations and had really weird behavior with watchPosition where the marker sometimes went going 1 km in a straight direction...
The constants are explained here for example https://developer.apple.com/documentation/corelocation/kcllocationaccuracybest (the better accuracy the more battery drain).
Guess it maybe is valid to reset this on a fail,
https://github.com/facebook/react-native/blob/master/Libraries/Geolocation/RCTLocationObserver.m#L319-L353
But also works to reset it while only fetching one position... but should not be reset when watching the position.
at least the iOS code seems to check for options.accuracy, which is not documented. please try navigator.geolocation.watchPosition(..., ..., { accuracy: 0 });
Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!
If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:
If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.
Did anyone find a good solution for this? I'm using RN 0.42 and the app isn't using my GPS location. The accuracy is stuck on 65m, but when running Google Maps in the background I get 10m.
@jcharlet @mo22 @Mellemel
I'm running expo with react-native, when I make the changes to the corresponding files in react-native/Libraries/Geolocation folder how do I recompile it? Because right now I'm just getting a constant accuracy of 65 on iOS and it's doing my head in!
Most helpful comment
Yes, the distanceFilter should work, but if you look lower down in the file you will notice they are doing the math and resetting it back to the default. Hence my fast easy fix for my application was to set the default to 0.