Skip to content

Commit

Permalink
added location as tag in TTNewlocation class
Browse files Browse the repository at this point in the history
  • Loading branch information
chandrakant naik committed Nov 14, 2019
1 parent e00ad3a commit ed671e3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ private void startLocationUpdates() {
//have the context but it might be running in the background
try {
requestLocationUpdates();
}
catch (Exception e) {
} catch (Exception e) {
Log.e(TAG, "startLocationUpdates: Error occurred might be since there is no activity attached");
locationUpdateStarted = false;
}
Expand All @@ -163,8 +162,7 @@ public void onSuccess(LocationSettingsResponse locationSettingsResponse) {
//noinspection MissingPermission
if (!getActivityCallback().checkSelfPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION)) {
getActivityCallback().requestPermissions(new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_PERMISSIONS_REQUEST_CODE);
}
else {
} else {
requestLocationUpdates();
}
}
Expand Down Expand Up @@ -262,7 +260,10 @@ private boolean filterAndAddLocation(Location location) {
float horizontalAccuracy = location.getAccuracy();
if (horizontalAccuracy > 10) { //10meter filter
// inaccurateLocationList.add(location);
disposeBag.notifyAll(new TTNewLocation(location.getLatitude(), location.getLongitude(), false, location.getAccuracy(), location.getBearing(),location.getAltitude())); return false;
TTNewLocation newLocation = new TTNewLocation(location.getLatitude(), location.getLongitude(), false, location.getAccuracy(), location.getBearing(), location.getAltitude());
newLocation.setTag(location);
disposeBag.notifyAll(newLocation);
return false;
}


Expand All @@ -286,6 +287,7 @@ private boolean filterAndAddLocation(Location location) {
predictedLocation.setLatitude(predictedLat);//your coords of course
predictedLocation.setLongitude(predictedLng);
predictedLocation.setAccuracy(kalmanFilter.get_accuracy());
predictedLocation.setBearing(location.getBearing());
float predictedDeltaInMeters = predictedLocation.distanceTo(location);

if (predictedDeltaInMeters > 60) {
Expand All @@ -305,9 +307,12 @@ private boolean filterAndAddLocation(Location location) {
+ "lon" + predictedLocation.getLongitude());
Log.d(TAG, "Location quality is good enough.");
//Code to notify all observers that we got a good location
disposeBag.notifyAll(new TTNewLocation(predictedLocation.getLatitude()
TTNewLocation newLocation = new TTNewLocation(predictedLocation.getLatitude()
, predictedLocation.getLongitude(), true, predictedLocation.getAccuracy()
,location.getBearing(),location.getAltitude())); return true;
, location.getBearing(), location.getAltitude());
newLocation.setTag(location);
disposeBag.notifyAll(newLocation);
return true;
}

public void addObserver(DisposableObserver<TTNewLocation> observer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class TTNewLocation {
private Double lat, lng,altitude;
private Boolean isAccurate;
private Float accuracy,bearing;
private Object tag;

public TTNewLocation(Double lat, Double lng, Boolean isAccurate, Float accuracy, Float bearing, Double altitude) {
this.lat = lat;
Expand Down Expand Up @@ -61,5 +62,13 @@ public Float getBearing() {
public void setBearing(Float bearing) {
this.bearing = bearing;
}

public Object getTag() {
return tag;
}

public void setTag(Object tag) {
this.tag = tag;
}
}

0 comments on commit ed671e3

Please sign in to comment.