Hi Edgar, the code is working as intended, but I think it would be nice that Expo.Location.getCurrentPositionAsync method could take a timeout parameter (or at least handle the case internally) to avoid to wait forever in case the GPS can’t provide a position.
@outatime – there is actually a timeout parameter that is only used on Android (on iOS) it’s ignored. This isn’t documented because of the platform difference. This could work for you?
Hi guys, is there any way to stop getCurrentPositionAsync while in progress?
I am using the timeout solution (Promise.race) given by OP, but unfortunately if position can’t be obtained it will look for it forever. Navigating away does not help.
The location marker symbol in the status bar will appear and stay there indefinitely (or at least until a fix is obtained).
I also tried the timeout parameter in options but it’s still the same - looking for a fix even though it times out.
@nikki please have a look at this. I hope you find it useful. It seems to me ‘timeout’ must be mentioned as a required parameter for getCurrentPostionAsync in docs
or prepareLocationRequest in LocationHelpers.java should call setExpirationDuration(long) or setExpirationTime(long) as per google’s LocationRequest docs
com.google.android.gms.location.LocationRequest please find its documentation as i am limited to 2 links only on comments. i have copied just a paragraph for reference.
" When using this(setNumUpdates) option care must be taken to either explicitly remove the request when no longer needed or to set an expiration with (setExpirationDuration(long) or setExpirationTime(long). Otherwise in some cases if a location can’t be computed, this request could stay active indefinitely consuming power. "
@ExpoMethod
public void getCurrentPositionAsync(final Map<String, Object> options, final Promise promise) {
// Read options
final Long timeout = options.containsKey("timeout") ? ((Double) options.get("timeout")).longValue() : null;
final LocationRequest locationRequest = LocationHelpers.prepareLocationRequest(options);
...
...
static void requestSingleLocation(final LocationModule locationModule, final LocationRequest locationRequest, final TimeoutObject timeoutObject, final Promise promise) {
// we want just one update
locationRequest.setNumUpdates(1);
....
....