react-native-geolocation-service
react-native-geolocation-service copied to clipboard
Location request timed out most of the time.
Im using getCurrentPosition to get user location with following params.
enableHighAccuracy: false,
timeOut: 15000,
maximumAge: 10000,
Most of the time response will be Location request timed out. Only after getting the user location I can generate data based on that. Is there any way to fix this issue or should i try any other libraries.
If it's android, some reported that opening google maps once will solve this issue. For iOS, I'm not sure what the issue could be. Are you using emulator or actual device?
same issue i am facing in android Most of the time response will be Location request timed out
remove timeout option and see how much time it takes to get a fix on your location.
I am facing the same issue
@Agontuk i tried opening google maps and location was shown in the map. then opening the app did not fix the issue for me. im having this issue mostly on android m devices. is there any workaround to this. im still having this issue.
@Agontuk i tested on actual device and also on emulator. im having this issue only on android. IOS is working fine.
The default value for distanceFilter
is set to 0 meters, which might be causing this issue. It also doesnt make sense in low accuracy situations. I tried setting it to something like 250 meters and that fixed it for me. Might just be coincidence though.
@osamaaamer95 can you share the complete code here?
@Agontuk i tested on actual device and also on emulator. im having this issue only on android. IOS is working fine.
Like I said, remove the timeout option and then request location. See how much time your device needs to get a gps fix. If it can't get a fix, it's most likely a device issue.
@Agontuk this issue is mostly in marshmallow devices. when users open google maps they get the location. but in app they are not. and how can i tell the users that its the device's issue that they are not getting the location. :( i will remove the timeout and update it here.
@Agontuk this issue is mostly in marshmallow devices. when users open google maps they get the location. but in app they are not. and how can i tell the users that its the device's issue that they are not getting the location. :( i will remove the timeout and update it here.
It's not related to marshmallow, I'm still using marshmallow & have no issue getting location. Many other users also face this issue in different android versions. If you have any device that has this issue, you should check the native log and find if there's any gps/location related error.
I have this problem only with Android 10
still persist on MI series
I am facing the same issue but with IPhone any work around it ?
It seems that with regards to the issue that I'm seeing (timeouts, error code 3) if you unset maxAge
to undefined
, it will retrieve the last location found via google maps. However, it won't retrieve updated locations until google maps is opened again.
Same issue happened but for iOS. On Android its working fine
In my case it first return correct lat/lon then after timeout which set again call error section with time out error.
So I removed timeout section. seems like without any issue it works.
Tested : iOS (Simulator)
In my case it first return correct lat/lon then after timeout which set again call error section with time out error.
So I removed timeout section. seems like without any issue it works.
Tested : iOS (Simulator)
Its working. Thanks !
In my case, I need to restart location services every time, then it begins working again. But it's like, every time I start my app or I call the function, it needs restarting.
I am having the same issue on iOS 14.2 on an iPhone XS. Was also able to confirm this issue on another iPhone device by a different user in a different location (>15 miles away).
This only recently started happening after upgrading from 4.x to 5.11. I ended up downgrading back to 4.x and the issue doesn't persist anymore.
Master branch is now updated with the fix for iOS, please try & see if it works for you. I'll release a new version soon.
If it's android, some reported that opening google maps once will solve this issue. For iOS, I'm not sure what the issue could be. Are you using emulator or actual device?
Opening Google Maps (and getting direction from current location to any random location) works fine! First couple days when I installed this library, everything was okay. And then all my location requests were rejected due to timeout issue. I don't think this solution (mostly workaround) will require same efforts from other customers. If yes, this thing is inappropriate:-/
If it's android, some reported that opening google maps once will solve this issue. For iOS, I'm not sure what the issue could be. Are you using emulator or actual device? yes it is solving the issue but what if users download the my app do i have to tell them that open map before using this app..i am newbie though
I had only passed timeOut to the third parameter object of getCurrentPosition function. And the problem was solved.
set forceLocationManager = true
is work for me.
perhaps it's because google play service is not supported in China, not sure.
@Agontuk can you please take a look on this PR from react-native-community/geolocation package? I believe this might fix the timeout issues. I've already patched your package and running some tests.
patch:
diff --git a/node_modules/react-native-geolocation-service/android/src/main/java/com/agontuk/RNFusedLocation/FusedLocationProvider.java b/node_modules/react-native-geolocation-service/android/src/main/java/com/agontuk/RNFusedLocation/FusedLocationProvider.java
index e502919..9e50226 100644
--- a/node_modules/react-native-geolocation-service/android/src/main/java/com/agontuk/RNFusedLocation/FusedLocationProvider.java
+++ b/node_modules/react-native-geolocation-service/android/src/main/java/com/agontuk/RNFusedLocation/FusedLocationProvider.java
@@ -276,7 +276,7 @@ public class FusedLocationProvider implements LocationProvider {
if (isSingleUpdate) {
long timeout = locationOptions.getTimeout();
- if (timeout > 0 && timeout != Long.MAX_VALUE) {
+ if (timeout > 0 && timeout != 1000 * 60 * 10) {
timeoutHandler.postDelayed(timeoutRunnable, timeout);
}
}
diff --git a/node_modules/react-native-geolocation-service/android/src/main/java/com/agontuk/RNFusedLocation/LocationManagerProvider.java b/node_modules/react-native-geolocation-service/android/src/main/java/com/agontuk/RNFusedLocation/LocationManagerProvider.java
index c05b8c1..a1673aa 100644
--- a/node_modules/react-native-geolocation-service/android/src/main/java/com/agontuk/RNFusedLocation/LocationManagerProvider.java
+++ b/node_modules/react-native-geolocation-service/android/src/main/java/com/agontuk/RNFusedLocation/LocationManagerProvider.java
@@ -205,7 +205,7 @@ public class LocationManagerProvider implements LocationProvider {
);
if (isSingleUpdate) {
- if (timeout > 0 && timeout != Long.MAX_VALUE) {
+ if (timeout > 0 && timeout != 1000 * 60 * 10) {
timeoutHandler.postDelayed(timeoutRunnable, timeout);
}
}
diff --git a/node_modules/react-native-geolocation-service/android/src/main/java/com/agontuk/RNFusedLocation/LocationOptions.java b/node_modules/react-native-geolocation-service/android/src/main/java/com/agontuk/RNFusedLocation/LocationOptions.java
index c13406f..fcd9ada 100644
--- a/node_modules/react-native-geolocation-service/android/src/main/java/com/agontuk/RNFusedLocation/LocationOptions.java
+++ b/node_modules/react-native-geolocation-service/android/src/main/java/com/agontuk/RNFusedLocation/LocationOptions.java
@@ -55,7 +55,7 @@ public class LocationOptions {
: DEFAULT_DISTANCE_FILTER;
long timeout = map.hasKey("timeout")
? (long) map.getDouble("timeout")
- : Long.MAX_VALUE;
+ : 1000 * 60 * 10;
double maximumAge = map.hasKey("maximumAge")
? map.getDouble("maximumAge")
: Double.POSITIVE_INFINITY;
Make sure you guys are using async await :
export const fetchMyLocation = async () => { try { const location = await GetLocation?.getCurrentPosition({ enableHighAccuracy: true, timeout: 15000, // Set a timeout of 15 seconds maximumAge: 10000, }); return location; } catch (error) { // Handle the error here console.error("Location error:", error); throw error; // Rethrow the error to be caught where the function is called } };