-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to change update interval? #54
Comments
Hi, this libarary is only a wrapper on Google Play Services so you probably have to use LocationRequest to setup or change update interval. |
The question is if its need to have 2 LocationRequest one with slow intervals like 10 min and other LocationRequest object with faster location update intervals like 5 seconds. And to switch between intervals to unsubscribe old and make new subscription with other LocationRequest. Or its enough to have only one subscription with saved LocationRequest instance and to set new interval. You can test the last. If GMS not copy initial LocationRequest it will work.. |
Hi, I tried to implement dynamic interval as below, but i am not sure if i go the google play services part wrong or the Rx part wrong. MyLocation class
In my Service
|
I think the problem is that when you change location request settings you need to resubscribe to Google Play Services with updated location request. |
@mcharmas can you please provide an example code? |
@lordlinus Look at my advice on #67 : using switchOnNext would work, without changing the subscriber. |
@saiimons Could you provide an example? Your suggestion sounds nice, but I don't quite understand how to do it. |
I have just modified the source of
Whats your view on this change? public class LocationUpdatesObservable extends BaseLocationObservable<Location> {
private static final String TAG = LocationUpdatesObservable.class.getSimpleName();
public static LocationUpdateReconfigurableObservable createObservable(Context ctx, LocationRequest locationRequest) {
return new LocationUpdateReconfigurableObservable(new LocationUpdatesObservable(ctx, locationRequest));
}
private LocationRequest locationRequest;
private LocationListener listener;
private GoogleApiClient apiClient;
private Observer<? super Location> observer;
private AtomicBoolean wasGoogleClientReady = new AtomicBoolean(false);
private LocationUpdatesObservable(Context ctx, LocationRequest locationRequest) {
super(ctx);
this.locationRequest = locationRequest;
}
@Override
protected void onGoogleApiClientReady(GoogleApiClient apiClient, final Observer<? super Location> observer) {
this.apiClient = apiClient;
this.observer = observer;
requestLocationUpdates();
}
@Override
protected void onUnsubscribed(GoogleApiClient apiClient) {
removeLocationUpdates();
this.listener = null;
this.observer = null;
this.apiClient = null;
}
private void requestLocationUpdates() {
synchronized (wasGoogleClientReady) {
wasGoogleClientReady.set(true);
listener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
observer.onNext(location);
}
};
LocationServices.FusedLocationApi.requestLocationUpdates(apiClient, locationRequest, listener);
}
}
private void removeLocationUpdates() {
if (apiClient.isConnected()) {
LocationServices.FusedLocationApi.removeLocationUpdates(apiClient, listener);
}
}
private void reconfigureLocationUpdates(LocationRequest locationRequest) {
synchronized (wasGoogleClientReady) {
this.locationRequest = locationRequest;
if (wasGoogleClientReady.get()) {
removeLocationUpdates();
requestLocationUpdates();
}
}
}
public static class LocationUpdateReconfigurableObservable extends Observable<Location> {
private final LocationUpdatesObservable locationUpdatesObservable;
public LocationUpdateReconfigurableObservable(LocationUpdatesObservable locationUpdatesObservable) {
super(RxJavaHooks.onCreate(locationUpdatesObservable));
this.locationUpdatesObservable = locationUpdatesObservable;
}
public void reconfigure(LocationRequest request) {
locationUpdatesObservable.reconfigureLocationUpdates(request);
}
}
} |
I think laveraging what RxJava has to offer is better idea. For example flatmapping some kind of |
Hi, is it possible to change update location interval dynamically?
For some stage of the app I want it update like every 10 minutes, but some stage i need it to be like close to real- time.
Thank in advance!
The text was updated successfully, but these errors were encountered: