Respond to a real Android camera: watchPosition does not respond to enabling / disabling the location service

If the location service was turned off, initially watchPosition not called when it was turned on. As a workaround, I call navigator.geolocation.getCurrentPosition recursively if an error occurs.

Also, watchPosition not called when the location service is disabled.

In iOS, everything works as expected.

Any suggestions are welcome.

Tested on Galaxy Note 5 (Android 6.0.1) and various AVD emulators, respond to v0.33

android.permission.ACCESS_FINE_LOCATION included in AndroidManifest.xml

 initialGeolocation(){ delete this.androidLocation; navigator.geolocation.getCurrentPosition( (position) => { log('LOCATION getCurrentPosition success', position); deviceActions.geolocation(position); }, (error) => { log('LOCATION getCurrentPosition error', error.message || error); if (Platform.OS == 'android'){ this.androidLocation = setTimeout(this.initialGeolocation, 500); } }, { enableHighAccuracy: (Platform.OS == 'android') ? false : true, timeout: 10000, maximumAge: 500 } ); }, componentDidMount() { this.initialGeolocation(); this.watchID = navigator.geolocation.watchPosition( (position) => { log('LOCATION watchPosition success', position); deviceActions.geolocation(position); }, (error) => { log('LOCATION watchPosition error', error.message || error); }, { enableHighAccuracy: (Platform.OS == 'android') ? false : true, distanceFilter: 10, timeout: 10000, maximumAge: 500 } ); } 
+5
source share

Source: https://habr.com/ru/post/1257459/


All Articles