@Override public void onLocationChanged(Location location) { boolean updateLocation = true; Location prevLocation = placePickerFragment.getLocation(); if (prevLocation != null) { updateLocation = location.distanceTo(prevLocation) >= LOCATION_CHANGE_THRESHOLD; } if (updateLocation) { placePickerFragment.setLocation(location); placePickerFragment.loadData(true); } } @Override
float distance = l.distanceTo(lastLocation); Log.d(TAG, "Distance to last: " + distance); if (l.distanceTo(lastLocation) < minDistance && !force) { Log.d(TAG, "Position didn't change"); return; && l.distanceTo(lastLocation) < l.getAccuracy() && !force) { Log.d(TAG, "Accuracy got worse and we are still "
private float distanceBetween(LatLng latLng1, LatLng latLng2) { Location loc1 = new Location(LocationManager.GPS_PROVIDER); Location loc2 = new Location(LocationManager.GPS_PROVIDER); loc1.setLatitude(latLng1.latitude); loc1.setLongitude(latLng1.longitude); loc2.setLatitude(latLng2.latitude); loc2.setLongitude(latLng2.longitude); return loc1.distanceTo(loc2); }
@Override public void onLocationChanged(Location location) { if (lastLocation == null) { lastLocation = location; } distanceInMeters += location.distanceTo(lastLocation); lastLocation = location; }
/** * Check if location too close to null island to be real * * @param loc The location to be checked * @return boolean True if away from lat,lon of 0,0 */ public static boolean notNullIsland(Location loc) { return (nullIsland.distanceTo(loc) > NULL_ISLAND_DISTANCE); }
/** * Determine whether two locations can be treated as same location * @return true if the locations can be treated as same; false otherwise */ public boolean areSameLocations(@NonNull Location location1, @NonNull Location location2) { return location1.distanceTo(location2) < MAXIMAL_DISTANCE_SAME_LOCATION_DETERMINATION; }
private static final float MINIMUM_ACCURACY = 10; // If the accuracy of the measurement is worse than 10 meters, we will not take the location into account private static final float MINIMUM_DISTANCE_BETWEEN_POINTS = 20; // If the user hasn't moved at least 20 meters, we will not take the location into account private Location lastLocationloc; // ... public void onLocationChanged(Location mylocation) { if (mylocation.getAccuracy() < MINIMUM_ACCURACY) { if (lastLocationloc == null || lastLocationloc.distanceTo(mylocation) > MINIMUM_DISTANCE_BETWEEN_POINTS) { // Add the new location to your polyline lastLocationloc = mylocation; } } }
@Override public int compare(Localizable loc1, Localizable loc2) { float diff = mFromLocation.distanceTo(loc1.getLocation()) - mFromLocation.distanceTo(loc2.getLocation()); return diff > 0 ? 1 : diff < 0 ? -1 : 0; } }
private Location lastGoodLocation = null; // Other methods @Override public void onLocationChanged(Location loc) { if (lastGoodLocation == null || lastGoodLocation.distanceTo(loc) > loc.getAccuracy()) { lastGoodLocation = loc; // do something with loc } }
private static final float MINIMUM_ACCURACY = 10; private static final float MINIMUM_DISTANCE_BETWEEN_POINTS = 20; private Location lastLocationloc; // ... public void onLocationChanged(Location mylocation) { if (mylocation.getAccuracy() < MINIMUM_ACCURACY) { if (lastLocationloc == null || lastLocationloc.distanceTo(mylocation) > MINIMUM_DISTANCE_BETWEEN_POINTS) { // Add the new location to your polyline lastLocationloc = mylocation; } } }
double distance Location locationA = new Location(“point A”) locationA.setLatitude(latA) locationA.setLongitude(lngA) Location locationB = new Location(“point B”) locationB.setLatitude(latB) LocationB.setLongitude(lngB) distance = locationA.distanceTo(locationB)
private static boolean locationCompatibleWithClass(Location location, Set<Location> locClass, double accuracy) { for (Location other : locClass) { if ((location.distanceTo(other) - location.getAccuracy() - other.getAccuracy() - accuracy) < 0) { return true; } } return false; }
public double calculateSpeed(Location prev, Location curr, double lastSpeed) { double deltaDistance = curr.distanceTo(prev); double deltaTime = (curr.getTime() - prev.getTime()) / 1000.0; double speedInMph = deltaDistance / deltaTime * 2.2369; if (abs(speedInMph - lastSpeed) > lastSpeed/100*20) { //This check that the speed difference is no bigger than 20% of the last known valid speed return -9999; //Or anything that make signal a problem } return speedInMph; }
@Override public void onNext(List<Place> places) { if (BuildConfig.DEBUG) { Log.i(YourApplication.LOG_TAG, "PlaceRemoteProvider.onResponse"); } for (Place place : places) { place.setDistance(PlaceRemoteProvider.this.mCurrentLocation.distanceTo(place.getLocation())); } if (PlaceRemoteProvider.this.mCallback != null) { PlaceRemoteProvider.this.mCallback.onPlaceLoadFinished(places); } } });
Location areaOfIinterest = new Location; Location currentPosition = new Location; areaOfIinterest.setLatitude(aoiLat); areaOfIinterest.setLongitude(aoiLong); currentPosition.setLatitude(myLat); currentPosition.setLongitude(myLong); float dist = areaOfIinterest.distanceTo(currentPosition); return (dist < 10000);
OverlayItem item = mOverlays.get(index); GeoPoint mPoint = item.getPoint(); // get Point of your marker Location locationMy = m_MyLocationOverlay.getLastFix(); // get current location if (locationMy != null) { Location locationPoint = new Location(locationMy); locationPoint.setLatitude((double)mPoint.getLatitudeE6() / 1000000.0f); locationPoint.setLongitude((double)mPoint.getLongitudeE6() / 1000000.0f); String str = String.format("%.1f miles", locationMy.distanceTo(locationPoint) * 0.000621371192); // meters to miles }
public float getDistanceFloat(LatLng my_latlong, LatLng frnd_latlong) { Location l1 = new Location("One"); l1.setLatitude(my_latlong.latitude); l1.setLongitude(my_latlong.longitude); Location l2 = new Location("Two"); l2.setLatitude(frnd_latlong.latitude); l2.setLongitude(frnd_latlong.longitude); float distance = l1.distanceTo(l2); return distance; } private void moveCameraTo(GoogleMap mMap, LatLng currentLocation)
public float getDistanceFloat(LatLng my_latlong, LatLng frnd_latlong) { Location l1 = new Location("One"); l1.setLatitude(my_latlong.latitude); l1.setLongitude(my_latlong.longitude); Location l2 = new Location("Two"); l2.setLatitude(frnd_latlong.latitude); l2.setLongitude(frnd_latlong.longitude); float distance = l1.distanceTo(l2); return distance; } public double CalculationByDistance(double initialLat, double initialLong, double finalLat, double finalLong){
@Test public void testLocation() { Location loc = new Location("GPS"); loc.setLongitude(50); loc.setLatitude(8); Location loc2 = new Location("GPS"); loc2.setLongitude(50); loc2.setLatitude(9); assertEquals(110598.56, loc.distanceTo(loc2), 0.5); }
@Test public void testLocation() { Location loc = new Location("GPS"); loc.setLongitude(50); loc.setLatitude(8); Location loc2 = new Location("GPS"); loc2.setLongitude(50); loc2.setLatitude(9); assertEquals(110598.56, loc.distanceTo(loc2), 0.5); }