Skip to content
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

[iOS]Only able to obtain the location immediately when the app starts #300

Open
YaoHuiJi opened this issue Feb 25, 2024 · 4 comments
Open
Labels
question Further information is requested

Comments

@YaoHuiJi
Copy link

YaoHuiJi commented Feb 25, 2024

I encountered a strange problem that has left me very confused. My app is only able to get coordinates once through "watchPosition" when it starts up, and the retrieval speed is very fast (the small arrow icon at the status bar indicating location retrieval briefly turns blue and solid ). However, afterwards, it fails to retrieve the address again, whether through watchPosition or getCurrentPosition, and I no longer see the location icon in the status bar turning solid, it remains a hollow/outline icon

However, in the following scenarios, it is able to retrieve coordinates once again, but only once:

  1. Killing the app and then restarting it.
  2. Switching the app to the background, disabling any location-related settings such as GPS, Wi-Fi, cellular data, in the system settings, and then re-enabling them before returning to the app.

I suspect it may be related to the cellular or GPS signals on my phone. However, after testing various settings, such as enabling/disabling high accuracy or adjusting timeout settings, the problem persists. Additionally, other geo apps, such as Apple's Map or Reminder apps, or other map apps are able to obtain the correct location.

It looks like watchPosition and getCurrentPosition only get the address once when the application starts, and then never again, and each failed attempt results in the following error:

{"PERMISSION_DENIED": 1, "POSITION_UNAVAILABLE": 2, "TIMEOUT": 3, "code": 3, "message": "Unable to fetch location within 120.0s."}

The info.plist:
截屏2024-02-26 08 32 57

I'm out of my mind😫. I have no idea what's going on. Can someone give me some ideas? Any thought possible.

@YaoHuiJi YaoHuiJi added the question Further information is requested label Feb 25, 2024
@YaoHuiJi YaoHuiJi changed the title Only able to obtain the location immediately when the app starts [iOS]Only able to obtain the location immediately when the app starts Feb 25, 2024
@YaoHuiJi
Copy link
Author

YaoHuiJi commented Feb 26, 2024

I did some more testing and found that it seemed to be watchPosition, and once the app ran watchPosition listener, getCurrentPosition no longer return the coords, but always return an error 'Unable to fetch location within xxx s'. I've removed the use of watchPosition from the code, and now getCurrentPosition immediately gets the coordinates every time.

This also explains why my App was still getting coordinates 2 days ago, because I just added the watchPosition code yesterday, trying to make the update more timely, but I couldn't get coordinates anymore... It took me more than a day to find the cause, but I should have thought it was the watchPosition problem earlier.

I don't know why, but it seems like the problem is solved, and I'll do more testing, Don't use watchPosition and getCurrentPosition together, hopefully to help someone else with the same problem.

@aacamhi
Copy link

aacamhi commented Mar 7, 2024

@YaoHuiJi were you using getCurrentPosition and WatchPosition in the same component? Or are you saying you cant use them together in the same app or in the same stack.. im facing the same issue and my current implementation consists of a custom hook that executes getCurrentLocation or watchPosition depending of the needs of the screen, but im never using both methods on the same instance of the hook or the component that calls it.

@YaoHuiJi
Copy link
Author

YaoHuiJi commented Mar 7, 2024

@YaoHuiJi were you using getCurrentPosition and WatchPosition in the same component? Or are you saying you cant use them together in the same app or in the same stack.. im facing the same issue and my current implementation consists of a custom hook that executes getCurrentLocation or watchPosition depending of the needs of the screen, but im never using both methods on the same instance of the hook or the component that calls it.

In my case, getCurrentPosition can't return coords if watchPosition is listening. So I remove the watchPosition and use setInterval+getCurrentPosition to update coords regularly. Everything works fine now.

@aacamhi
Copy link

aacamhi commented Mar 7, 2024

@YaoHuiJi were you using getCurrentPosition and WatchPosition in the same component? Or are you saying you cant use them together in the same app or in the same stack.. im facing the same issue and my current implementation consists of a custom hook that executes getCurrentLocation or watchPosition depending of the needs of the screen, but im never using both methods on the same instance of the hook or the component that calls it.

In my case, getCurrentPosition can't return coords if watchPosition is listening. So I remove the watchPosition and use setInterval+getCurrentPosition to update coords regularly. Everything works fine now.

Ok, so im guessing my cleanup methods which clear the watch are probably not working as expected.. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants