Agontuk / react-native-geolocation-service

React native geolocation service for iOS and android
https://www.npmjs.com/package/react-native-geolocation-service
MIT License
1.61k stars 292 forks source link

IOS watchPosition take a long time before taking accurate coordinates with ios sending time out error #231

Open GuillaumeBordeau opened 3 years ago

GuillaumeBordeau commented 3 years ago

Hello, I have a problem with watchPosition on ios, but it works well on android. The problem is that it take some position correctly at the beginning (around 8/9) and then it stops working and just take coordinates like every 40/50 seconds with low precision. After some time (like 5 minutes) it finally takes coordinates like it should with very good precision. I also, when it takes 40 seconds to take coordinates, get an error message from ios that is not catch by watchPosition about a webSocket and a task timed out.

Here is the error : [connection] nw_socket_handle_socket_event [C38:1] Socket SO_ERROR [60: Operation timed out] 2020-12-16 14:14:52.548262+0100 App [2345:934511] [connection] nw_connection_get_connected_socket [C38] Client called nw_connection_get_connected_socket on unconnected nw_connection 2020-12-16 14:14:52.548378+0100 App [2345:934511] TCP Conn 0x282a0f230 Failed : error 0:60 [60] 2020-12-16 14:14:52.548676+0100 App[2345:934448] [native] Error occurred, shutting down websocket connection: Websocket exception Error Domain=NSPOSIXErrorDomain Code=60 "Operation timed out" UserInfo={_kCFStreamErrorCodeKey=60, _kCFStreamErrorDomainKey=1} 2020-12-16 14:15:01.047633+0100 App[2345:935353] Task <6856DEB6-9103-49EC-82DC-DB0F34DD96BB>.<88> finished with error [-1001] Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={_kCFStreamErrorCodeKey=-2102, NSUnderlyingError=0x281165590 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <6856DEB6-9103-49EC-82DC-DB0F34DD96BB>.<88>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask <6856DEB6-9103-49EC-82DC-DB0F34DD96BB>.<88>" ), NSLocalizedDescription=The request timed out., NSErrorFailingURLStringKey=http://172.16.0.24:8081/assets/src/assets/images/enregistrer_bouton.png?platform=ios&hash=17fc5e52f3414fb0a3f0cadc6bc10c51, NSErrorFailingURLKey=http://172.16.0.24:8081/assets/src/assets/images/enregistrer_bouton.png?platform=ios&hash=17fc5e52f3414fb0a3f0cadc6bc10c51, _kCFStreamErrorDomainKey=4} 2020-12-16 14:15:03.315051+0100 App[2345:935353] [connection] nw_socket_handle_socket_event [C41:1] Socket SO_ERROR [60: Operation timed out] 2020-12-16 14:15:03.316245+0100 App[2345:935563] [connection] nw_connection_get_connected_socket [C41] Client called nw_connection_get_connected_socket on unconnected nw_connection 2020-12-16 14:15:03.316402+0100 App[2345:935563] TCP Conn 0x282a1e890 Failed : error 0:60 [60]

And here is my code for watchPosition :

Geolocation.watchPosition((location) => {
                    console.log(' new coords', location)
                    asyncGetGps(location)
                },
                (error) => {
                    asyncGetGpsError(error)
                },
                {  distanceFilter: 1, accuracy: {
                    ios: 'best',
                    android: 'high'
                } })

I don't know if I did something wrong or if this is a normal behavior of the gps but in other app gps work normally and this code on android work fine too.

Sorry for the bad english and thank you in advance.

Agontuk commented 3 years ago

Not sure if the error is related to location. If it is, it probably means your device failed to get a location fix. Your code looks fine, can you check with a different device if possible ?