public LocationAssert hasAccuracy() { isNotNull(); assertThat(actual.hasAccuracy()) // .overridingErrorMessage("Expected to have accuracy but did not.") // .isTrue(); return this; }
public LocationAssert hasNoAccuracy() { isNotNull(); assertThat(actual.hasAccuracy()) // .overridingErrorMessage("Expected to not have accuracy but did.") // .isFalse(); return this; }
coordinates.put(PARAM_LATITUDE, location.getLatitude()); coordinates.put(PARAM_LONGITUDE, location.getLongitude()); if (location.hasAccuracy()) { coordinates.put(PARAM_ACCURACY, location.getAccuracy());
/** * Checks whether accuracy is good enough by testing whether accuracy is available and below settings threshold * * @param location * @return true if location has accuracy that is acceptable */ private boolean acceptableAccuracy(final Location location) { return location.hasAccuracy() && (location.getAccuracy() <= Float.parseFloat( prefs.getString(Preferences.KEY_REQ_GPS_ACCURACY, Preferences.VAL_REQ_GPS_ACCURACY))); }
/** * Check whether the location info is accurate enough in order to be used */ private boolean isAccurateLocation(@Nullable Location location) { if (location != null && location.hasAccuracy() && location.getAccuracy() < MINIMUM_ACCEPTABLE_LOCATION_ACCURACY_METERS) { return true; } else { return false; } }
@Override public void onLocationChanged(Location location) { if (!location.hasAccuracy()) { return; } if (location.getAccuracy() > 5) { return; } // do something with location accurate to 5 meters here. }
@Override public void onLocationChanged(Location location) { if (!location.hasAccuracy()) { return; } if (location.getAccuracy() > 4) { return; } //process location accurate to 4 meters }
@Override public void onLocationChanged(Location location) { if(location.hasAccuracy() && location.getAccuracy() < 100F) { // the location has accuracy and has an accuracy span within 100m radius // do whatever you want with this location and stop location listener stopLocationUpdates(); } // if the above code did not get executed, the location listener will work // until a location with acceptable accuracy is obtained }
private boolean horribleGps(final Location location) { // try to protect against some horrible gps's out there // check if accuracy is under 10 miles boolean horrible = location.hasAccuracy() && location.getAccuracy() > 16000; horrible |= location.getLatitude() < -90 || location.getLatitude() > 90; horrible |= location.getLongitude() < -180 || location.getLongitude() > 180; return horrible; }
@Override public void onLocationChanged(Location location) { int suitableMeter = 20; // adjust your need if (location.hasAccuracy() && location.getAccuracy() <= suitableMeter) { // This is your most accurate location. } }
@Override public void onLocationChanged(Location location) { if (!location.hasAccuracy()) { return; } if (location.getAccuracy() > 10) { //possibly tell user gps accuracy with transparent circle like the maps //application does. return; } //process location accurate to 10 meters here }
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 5, myLocationListener); // "myLocationListener" must be an object from a class that implements LocationListener // "myLocationListener" implementation of LocationListener.onLocationChanged public void onLocationChanged(Location location) { int MIN_ACCURACY = 5; // in metters if ((!location.hasAccuracy()) || (location.getAccuracy() > MIN_ACCURACY)) { // discard this location and keep listening to new location readings } else { // that's a good reading! // do somethings you want... blah, blah, blah... // stop updates when you get the location to preserve users' battery. locationManager.removeUpdates(myLocationListener); } }
public float getAccuracy() { return _Location.hasAccuracy() ? _Location.getAccuracy() : NOT_AVAILABLE; } public float getBearing() { return _Location.hasBearing() ? _Location.getBearing() : NOT_AVAILABLE; }
public LocationAssert hasAccuracy() { isNotNull(); assertThat(actual.hasAccuracy()) // .overridingErrorMessage("Expected to have accuracy but did not.") // .isTrue(); return this; }
public LocationAssert hasNoAccuracy() { isNotNull(); assertThat(actual.hasAccuracy()) // .overridingErrorMessage("Expected to not have accuracy but did.") // .isFalse(); return this; }
@Subscribe public void onEvent(onLocationUpdate event) { if (event.location == null) { return; } if (event.location.hasAccuracy()) { Log.v(TAG, "GPS Accuracy " + event.location.getAccuracy()); tvAccuracy.setText(ACCURACY_FORMAT.format(event.location.getAccuracy()) + getResources().getString(R.string.meter)); } else { tvAccuracy.setText(getResources().getString(R.string.empty)); } }
private static String accuracyAddendum() { return lastLocation.hasAccuracy() ? " (+/- " + JoH.qs(lastLocation.getAccuracy(), 0) + "m)" : ""; }
private static String accuracyAddendum() { return lastLocation.hasAccuracy() ? " (+/- " + JoH.qs(lastLocation.getAccuracy(), 0) + "m)" : ""; }
public boolean isUsable(Location location) { return location!=null && location.hasAccuracy() && location.getAccuracy() < 800 && location.getSpeed() > 0; }
private boolean isLocationFixed(GpsIconData icon) { if (ContextCompat.checkSelfPermission(icon.getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { Location location = icon.locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); return location != null && (getElapsedTime(location) < 3000 || location.hasAccuracy()); } else return false; }