Reputation: 43
I've managed to successfully use the geolocation API in React Native, but when I turn my location off the error callback doesn't seem to work. I've tried providing a timeout option of 5 seconds and I could wait all day and the error would never be called. The weird thing is the error callback will be called if I turn the location back on. It will go to the error callback, then go back to the success.
I've tried using the following code:
navigator.geolocation.getCurrentPosition(
(position) => {
console.log("Got Position");
},
(error) => {
console.log("Got error");
}
);
navigator.geolocation.getCurrentPosition(
(position) => {
console.log("Got Position");
},
(error) => {
console.log("Got error");
},
{timeout: 5000}
);
I've also tried using the "react native android location services dialog box" module, but get the following error and just gave up:
android\app\src\main\java\com\orchardapp\MainApplication.java:7: error: package com.showlocationservicesdialogbox does not exist
import com.showlocationservicesdialogbox.LocationServicesDialogBoxPackage;
^
android\app\src\main\java\com\orchardapp\MainApplication.java:30: error: cannot find symbol
new LocationServicesDialogBoxPackage(),
^
symbol: class LocationServicesDialogBoxPackage
2 errors
I'm building the app on an android 6 device. Just kind of stuck now and not sure what else to use... Has anyone experienced this and got some tips?
Thanks!
Upvotes: 2
Views: 664
Reputation: 43
So the issue seemed to be the version of React Native I was using. I updated it from 0.44 to 0.46 and the error magically worked. Most likely would have been because I was using an older version of the module, which could have been incompatible with some of the stuff I had in the code. :/
Anyway problem solved by updating!
Upvotes: 1