patloew / RxLocation

🗺 [DEPRECATED] Reactive Location APIs Library for Android and RxJava 2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question: Get location ONCE on button click

Shahar2k5 opened this issue · comments

I want to get a fresh location whenever the user's clicking a button.
I got this code, but sometimes it returns the old location (Also tested with emulator)
How can I force new location?
And also, on every click, the location update takes different time, sometimes 1 second, sometime 7 seconds, is that normal (Same device, same location, same session)?
This is my code inside the onClick:

        locationRequest = LocationRequest.create()
                .setNumUpdates(1)
                .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
        locationDisposable = rxLocation.location().updates(locationRequest)
                .firstElement()
                .subscribeOn(Schedulers.io())
                .timeout(LOCATION_TIMEOUT_IN_SECONDS, TimeUnit.SECONDS, AndroidSchedulers.mainThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe({ location ->
                    info { "location is: $location" }
                    status.setValue(Status.LocationUpdate(location))
                }, {
                    it.printStackTrace()
                })```

Hi, the code is correct. However, this library cannot influence how often and when location updates are provided via the Play Services Fused Location Provider (which is wrapped by this library).

Hello, my question is very similar to yours. I need the GSP service to be always on. The user saves the current location with one click, but there is no good idea.