-
Notifications
You must be signed in to change notification settings - Fork 5.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Location.getCurrentPositionAsync() sometimes never responds or takes a very long time to respond #10756
Comments
Hey @rvieceli, you mention this occurred after upgrading...have you been able to reproduce this with a newly created SDK39 project as well? |
@AdamJNavarro I'm wrong. We got this issue after upgrade to SDK39 in standalone QA app, but I done right now a test in production with SDK38 and I had the same issue. Maybe is related with iOS14. I'm trying to download a iOS 13 simulator, but my internet don't help me. |
@AdamJNavarro We tested with Iphone 11 (ios14) and iphone 6 (ios12) and in both cases in SDK38 (prod) are fast, but in SDK39 (qa) are slow. |
@AdamJNavarro We discovery more things during the investigation. When Precise Location is OFF, SDK 38 and 39 are very slow, if we turn ON works fine in SDK38, but SDK39 is slow. |
I'm 100% sure if is related, but after our test in SDK38, we got this error in sentry |
Try set accuracy low as below:
I set Location.Accuracy.Balanced, which caused long time to get location sometimes. https://forums.expo.io/t/location-getcurrentpositionasync-takes-10-seconds/19714/3 |
@tenondecrpc I need to show user position on the map, I need more precision. I will test it again |
@rvieceli I tried passing it balanced as value, and even that value worked for me, a higher value gave problems. This is my code now, including the request for permission to the user: // Get permissions // Get location |
I am facing the same issue. Every time it takes more than 10 seconds in iOS to get location data. |
We're getting the same issue since upgrading to 39. Our app has gotten very slow at getting a response back from this call. |
I followed the steps in the documentation as well as the lines stated above, but I still am stuck at "Waiting" for the location, never receiving the value |
Using this example https://docs.expo.io/versions/latest/sdk/location/#usage from documentation I created this snack https://snack.expo.io/@rvieceli/expo-issue-10756 I only added time result below the location result. Android takes ~0.051 seconds to get my location |
I also tested different SDK versions. Using Precise Location as ON Using Precise Location as OFF |
are there any updates? |
For me, I just forgot to turn on the emulator's location, but no problem |
Hey @maralihart, awesome! My problem is also in production with standalone app. Can you share with us our permissions, dependencies (only from expo) and your implementation if is different from expo documentation? Thank you. have a nice day! |
Getting location was working fine for me on sdk 36 but upgrading to sdk 40 slowed it down to 10+ seconds. Any word from Expo on fixing this bug? |
I am also experiencing this problem. Is there an update please? |
I am using SDK39, and having the same issue. any solution, plz? |
I am using SDK 40, In my case speed is a bit faster but anyway is not really acceptable: 4-6 seconds. |
So it seems that this is not a bug, and the documentation mentions this (https://docs.expo.io/versions/latest/sdk/location/).. What I ended up doing is using getLastKnownPositionAsync(), which is fast, to get the map started and then running getCurrentPositionAsync() in the background to get the more accurate location. Not the most elegant solution, but helps out. |
FYI this did not fix the issue for me on iOS 14.4.2 with Expo Go 2.19.3 and SDK 41. Latency is still ~11-12 seconds per API call. (Note when permission is being requested, iOS shows me a live preview of my current location so clearly has it already resolved to some - seemingly fine - resolution). getLastKnownPositionAsync() does work for me in low latency on with these versions. Thanks @migueladelgado (Minor note that getLastKnownPositionAsync didn't seem to work with RNWeb so I ended up using |
Live preview when IOS request permission is not under expo control. But you can have the same faster resolve using react-native-maps (showing user position). |
this sped it up for me but 100 meters is a bit problematic for my use case. |
Any update here? We have the same issue in the latest expo SDK and we would like to use a high accuracy. Thanks for your help. |
Wanted to follow up here, any update? Same issue, looking for alternatives at the moment Thanks friends |
Still experiencing this issue on v 42. I'll give the getLastKnownPositionAsync work around a shot. |
I decided switch back to react-native-geolocation-service |
@MattZ6 I'm not understanding why the increment should be outside the try/catch do {
try {
location = await Promise.race([
delay(DELAY_IN_MS),
Location.getCurrentPositionAsync(locationOptions)
]);
if (!location) {
throw new Error("Timeout"); // <---------- if you are thrown an error here it will be caught in catch below I think.
}
} catch (err) {
locationError = err as Error;
tries += 1; // 👈 can't we increment here?
}
} while (!location && tries <= MAX_TRIES); The overall pattern seems to work well though! |
Hey @janusqa! Feel free to change it! The number of attempts to increment in the The final code I'm using is still a little different from this :D |
depends on you need whether you want to increase only when error or both situations(success,error) |
Hey folks, just a side note, if you're not using |
Hi guys,
|
@sk-phan , it works perfectly for me in dev build as well, however on release build it takes more than 10 seconds in iOS. |
Hi, i'm facing almost the same issue, expo-location works fine for me in dev with Location.getCurrentPositionAsync() or Location.getLastKnownPositionAsync() but it doesn't work on production. I'm on SDK 49 and expo-location 16.1.0, i've tried many things including the solution of @sk-phan, or change the play-services-location version in the build.gradle to 20 or 21.0.1. Nothing worked. I managed to get the error message that shows only on production: Error: Encountered an exception while calling native method: Exception occurred while executing exported method getLastKnownPositionAsync on module Expo Location: Found interface com.google.android.gms.lo cation.FusedLocation ProviderClient, but class was expected (declaration of 'com.google.android.gms.locati on.FusedLocation ProviderClient' appears in /data/app/ I don't know what to do anymore, i'm on free plan on Expo and i've done my 30 builds this month just to try to resolve this issue, if someone has an new idea, i would like to test it... next month 🤣 |
@m-regragui We decided to use Location.watchPositionAsync, instead of Location.getCurrentPositionAsync(). And it is much faster to retrieve the data. Works great on IOS and Android. |
@m-regragui could you share how you set up the Expo watchLocation ? Maybe I can help |
@sk-phan Thanks for your reply, I tried with Location.watchPositionAsync:
And I have the same issue with Location.getLastKnownPositionAsync(). It works on dev but on production I catch this error: Error: Encountered an exception while calling native method: Exception occurred while executing exported method watchPositionImplAsync on module ExpoLocation: Found interface com.google.android.gms.lo cation.FusedLocationProviderClient, but class was expected (declaration of 'com.google.android.gms.locati on.FusedLocation ProviderClient' appears in /data/app/ I use SDK 49 with expo-location 16.1.0 and managed workflow with eas build |
@m-regragui I am not able to reproduce the issue. However, with your current code, it crashed the app for undefined reason in my local build as the subscription never stopped. In this case, I run expo prebuild in my local env. I added minor code improvement below. Hopefully, it helps and you will find a solution to your issue soon.
If possible, try to add a time interval for the location watcher. |
@sk-phan @m-regragui Hi,bor. I use
|
The one above worked for me and It is fast on both, but sometimes the location can't be fetched and I don't know why |
what's the difference between the if and else condition. Also i can't find that flag Can @expo-bot Expo team please take look at this long pending issues from Expo Location 🥺 |
the difference between the if and else is that on ios if you use getCurrentPositionAsync it will takes a long time to fetch the location of the user, so you have to handle it like this, but the problem is some times it doesn't take the location and you have to close the app and open it again and I don't know why and how to fix it |
You guys may need!
|
If anybody is still struggling with this problem, I think I found a quite good workaround.
I am developing an app in which I need to locate the user on the map before showing him the map itself, and I was experiencing a situation in which the map would load, and only after a few seconds (as many others pointed out) the map animated in order to reach the newly read user position, which resulted in an horrible user experience. I fundamentally decided to use To be completely sure that my app would have read the user position before using the Hope this helps, worked good for my use-case! |
Where to upvote this fix request ? Because that's getting very annoying for an so essential features ! |
@DevicyKenitou I just gave up on this library and moved to another one after a few years. ⌛ |
Oh which one do you use or recommend that is not too complicated to use/configure on an expo rn project ? That work well for both iOS and Android ? |
IMO the best one nowadays is React Native Background Geolocation. Works quite well in both platforms 👍🏽 |
Well that's a paid one ... And I don't need the "watch position" features, just need to fetch the location of the user when needed and not constantly fetching for the location |
i'm using React Native Background Geolocation for just Geofencing and Background Fetching. Do you recommend removing the expo-location completely and use the Also trying out this fix recommended above to use watchPositionAsync, seems to work well in testing env. |
If you are in China, you can try to convert the WGS84 coordinates from your IOS to GCJ102. |
I'm experiencing this problem as well. Any updates? (whispering) |
🐛 Bug Report
I have slow performance on iOS (14), using Expo App (simulator - 11 and real device - 6s) or Standalone (real device - 6s).
Tried to add accuracy to Lowest, but I had same issue.
Works fine on Android.
Environment - output of
expo diagnostics
& the platform(s) you're targetingReproducible Demo
Snack reproducible demo -> https://snack.expo.io/@rvieceli/expo-issue-10756
The text was updated successfully, but these errors were encountered: