Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

Location timeout #10

Open
prajapatiravi257 opened this issue Jun 16, 2018 · 4 comments
Open

Location timeout #10

prajapatiravi257 opened this issue Jun 16, 2018 · 4 comments

Comments

@prajapatiravi257
Copy link

How to add a timeout in observable of lastlocation() call if it's taking to much time to get location

@bluetoothfx
Copy link

I am not sure if it will work or not. But please let me know if it works. Thanks.

  RxLocation rxLocation = new RxLocation(this);
  rxLocation.setDefaultTimeout(25,TimeUnit.SECONDS);
  final RxGps rxGps = new RxGps(rxLocation,this);

rxGps.lastLocation()
                .doOnSubscribe(this::addDisposable)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(location -> {
                    locationText.setText(location.getLatitude() + ", " + location.getLongitude() + ", " + location.getProvider());
                }, throwable -> {
                    if (throwable instanceof RxGps.PermissionException) {
                        displayError(throwable.getMessage());
                    } else if (throwable instanceof RxGps.PlayServicesNotAvailableException) {
                        displayError(throwable.getMessage());
                    }
                });

@prajapatiravi257
Copy link
Author

Sure, I will give it a try. Thanks BTW

@prajapatiravi257
Copy link
Author

It works but is there any which can inform timeout occurred while fetching location

@bluetoothfx
Copy link

bluetoothfx commented Jul 20, 2018

I did not find any but you may add timeout function and then check exactly after that time if Latitude and Longitude is null or not. I hope this may work.

rxGps.lastLocation()
.timeout(10, TimeUnit.SECOND)
.doOnSubscribe(this::addDisposable)
........................................................................
...............

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants