Open prajapatiravi257 opened 6 years ago
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());
}
});
Sure, I will give it a try. Thanks BTW
It works but is there any which can inform timeout occurred while fetching location
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) ........................................................................ ...............
How to add a timeout in observable of lastlocation() call if it's taking to much time to get location