react-native-geolocation-service icon indicating copy to clipboard operation
react-native-geolocation-service copied to clipboard

Location request timed out most of the time.

Open salmanxoxo opened this issue 4 years ago • 27 comments

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.

salmanxoxo avatar Apr 23 '20 11:04 salmanxoxo

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?

Agontuk avatar Apr 24 '20 11:04 Agontuk

same issue i am facing in android Most of the time response will be Location request timed out

sombizbuzzz avatar Apr 27 '20 19:04 sombizbuzzz

remove timeout option and see how much time it takes to get a fix on your location.

Agontuk avatar Apr 30 '20 12:04 Agontuk

I am facing the same issue

ASIF-Mahmud1 avatar May 08 '20 13:05 ASIF-Mahmud1

@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.

salmanxoxo avatar May 11 '20 17:05 salmanxoxo

@Agontuk i tested on actual device and also on emulator. im having this issue only on android. IOS is working fine.

salmanxoxo avatar May 11 '20 17:05 salmanxoxo

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 avatar May 12 '20 19:05 osamaaamer95

@osamaaamer95 can you share the complete code here?

salmanxoxo avatar May 14 '20 12:05 salmanxoxo

@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 avatar May 14 '20 17:05 Agontuk

@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.

salmanxoxo avatar May 15 '20 09:05 salmanxoxo

@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.

Agontuk avatar May 16 '20 09:05 Agontuk

I have this problem only with Android 10

Kamill90 avatar May 24 '20 17:05 Kamill90

still persist on MI series

manjeets12 avatar Jul 08 '20 12:07 manjeets12

I am facing the same issue but with IPhone any work around it ?

aelbawab avatar Jul 21 '20 14:07 aelbawab

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.

cjpete avatar Jul 24 '20 15:07 cjpete

Same issue happened but for iOS. On Android its working fine

amirulasrof avatar Sep 25 '20 07:09 amirulasrof

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)

kgsachinthaudara avatar Oct 12 '20 20:10 kgsachinthaudara

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 !

amirulasrof avatar Oct 16 '20 03:10 amirulasrof

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.

angelod1as avatar Nov 25 '20 19:11 angelod1as

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.

todesignandconquer avatar Jan 09 '21 00:01 todesignandconquer

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.

Agontuk avatar Jan 11 '21 19:01 Agontuk

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:-/

sergeylaptev avatar Apr 07 '21 19:04 sergeylaptev

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

aman-275 avatar Jun 01 '21 19:06 aman-275

I had only passed timeOut to the third parameter object of getCurrentPosition function. And the problem was solved.

phucgo240699 avatar Nov 24 '21 03:11 phucgo240699

set forceLocationManager = true is work for me. perhaps it's because google play service is not supported in China, not sure.

simonNeo avatar Sep 29 '22 09:09 simonNeo

@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;


efstathiosntonas avatar Dec 08 '22 16:12 efstathiosntonas

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 } };

DevHamzaShahid avatar Aug 11 '23 06:08 DevHamzaShahid