Skip to content

Instantly share code, notes, and snippets.

@fayimora
Created June 23, 2016 16:49
Show Gist options
  • Save fayimora/39b84d022bd05b97182cfcf08605d121 to your computer and use it in GitHub Desktop.
Save fayimora/39b84d022bd05b97182cfcf08605d121 to your computer and use it in GitHub Desktop.
public class LocationServiceF extends IntentService {
private static final String TAG = "LocationService";
private Pubnub pubnub;
private Rider currentRider;
public LocationServiceF() {
super("LocationService");
}
@Override
protected void onHandleIntent(Intent intent) {
Log.d(TAG, "onHandleIntent()");
currentRider = Rider.currentRider(this);
pubnub = new Pubnub(getString(R.string.com_pubnub_publishKey), getString(R.string.com_pubnub_subscribeKey));
LocationRequest request = LocationRequest.create() //standard GMS LocationRequest
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setNumUpdates(5)
.setInterval(100);
ReactiveLocationProvider locationProvider = new ReactiveLocationProvider(this);
locationProvider.getUpdatedLocation(request)
.subscribeOn(Schedulers.computation())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<Location>() {
@Override
public void onCompleted() {
Log.d(TAG, "OnCompleted");
}
@Override
public void onError(Throwable e) {
Log.d(TAG, e.getMessage());
}
@Override
public void onNext(Location location) {
double lng = location.getLongitude();
double lat = location.getLatitude();
String msg = String.format(Locale.UK, "Driver: %s\nLongitude: %f\nLatitude: %f", currentRider.getFirstName(), lng, lat);
Log.d(TAG, msg);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment