private Location getLastKnownLocation() { List<String> providers = mLocationManager.getProviders(true); Location bestLocation = null; for (String provider : providers) { Location l = mLocationManager.getLastKnownLocation(provider); ALog.d("last known location, provider: %s, location: %s", provider, l); if (l == null) { continue; } if (bestLocation == null || l.getAccuracy() < bestLocation.getAccuracy()) { ALog.d("found best last known location: %s", l); bestLocation = l; } } if (bestLocation == null) { return null; } return bestLocation; }
@Override public void onLocationChanged(Location location) { if (freshLocation == null) { if (location.getAccuracy() < params.getLocationMaxAccuracyMeters()) { synchronized (scanLock) { freshLocation = location; scanLock.notify(); } } } }
LocationManager mLocationManager; Location myLocation = getLastKnownLocation(); private Location getLastKnownLocation() { mLocationManager = (LocationManager)getApplicationContext().getSystemService(LOCATION_SERVICE); List<String> providers = mLocationManager.getProviders(true); Location bestLocation = null; for (String provider : providers) { Location l = mLocationManager.getLastKnownLocation(provider); if (l == null) { continue; } if (bestLocation == null || l.getAccuracy() < bestLocation.getAccuracy()) { // Found best last known location: %s", l); bestLocation = l; } } return bestLocation; }
public LocationAssert hasAccuracy(float accuracy) { isNotNull(); float actualAccuracy = actual.getAccuracy(); assertThat(actualAccuracy) // .overridingErrorMessage("Expected accuracy <%s> but was <%s>.", accuracy, actualAccuracy) // .isEqualTo(accuracy); return this; }
class LocationSerializer implements JsonSerializer<Location> { public JsonElement serialize(Location t, Type type, JsonSerializationContext jsc) { JsonObject jo = new JsonObject(); jo.addProperty("mProvider", t.getProvider()); jo.addProperty("mAccuracy", t.getAccuracy()); // etc for all the publicly available getters // for the information you're interested in // ... return jo; } } class LocationDeserializer implements JsonDeserializer<Location> { public Location deserialize(JsonElement je, Type type, JsonDeserializationContext jdc) throws JsonParseException { JsonObject jo = je.getAsJsonObject(); Location l = new Location(jo.getAsJsonPrimitive("mProvider").getAsString()); l.setAccuracy(jo.getAsJsonPrimitive("mAccuracy").getAsFloat()); // etc, getting and setting all the data return l; } }
coordinates.put(PARAM_LONGITUDE, location.getLongitude()); if (location.hasAccuracy()) { coordinates.put(PARAM_ACCURACY, location.getAccuracy());
return; if (l.getAccuracy() >= lastLocation.getAccuracy() && l.distanceTo(lastLocation) < l.getAccuracy() && !force) { Log.d(TAG, "Accuracy got worse and we are still "
int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy()); boolean isLessAccurate = accuracyDelta > 0; boolean isMoreAccurate = accuracyDelta < 0;
private Location copyOf(Location location) { if (location == null) return null; Location copy = new Location(location); copy.setAccuracy(location.getAccuracy()); copy.setAltitude(location.getAltitude()); copy.setBearing(location.getBearing()); copy.setExtras(location.getExtras()); copy.setLatitude(location.getLatitude()); copy.setLongitude(location.getLongitude()); copy.setProvider(location.getProvider()); copy.setSpeed(location.getSpeed()); copy.setTime(location.getTime()); return copy; }
private void updateLocation(Location location) { if (location != null) { this.location = location; latitude.setText(String.valueOf(location.getLatitude())); longitude.setText(String.valueOf(location.getLongitude())); accuracy.setText(String.valueOf(location.getAccuracy()) + "m"); final Date date = new Date(location.getTime()); final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); time.setText(sdf.format(date)); provider.setText(location.getProvider()); } else { latitude.setText(R.string.dd_debug_drawer_location_empty); longitude.setText(R.string.dd_debug_drawer_location_empty); accuracy.setText(R.string.dd_debug_drawer_location_empty); time.setText(R.string.dd_debug_drawer_location_empty); provider.setText(R.string.dd_debug_drawer_location_no_provider); } }
private void updateAccuracy() { if(accuracyMarker != null && lastLocation != null && accuracyMarker.isVisible()) { LngLat pos = new LngLat(lastLocation.getLongitude(), lastLocation.getLatitude()); float size = meters2Pixels(pos, lastLocation.getAccuracy()); accuracyMarker.setStylingFromString("{ style: 'points', color: 'white', size: ["+size+"px, "+size+"px], order: 2000, flat: true, collide: false }"); } }
if (gps_loc.getAccuracy() > net_loc.getAccuracy()) finalLoc = net_loc; else
private boolean isWithinSurveyDistance(long questId, QuestGroup group, @Nullable Location location) { ElementGeometry geometry = getQuestGeometry(questId, group); if(geometry == null || location == null) return false; LatLon loc = new OsmLatLon(location.getLatitude(), location.getLongitude()); FlattenIterable<LatLon> itb = new FlattenIterable<>(LatLon.class); if(geometry.polygons != null) itb.add(geometry.polygons); else if(geometry.polylines != null) itb.add(geometry.polylines); else itb.add(Collections.singleton(geometry.center)); for (LatLon pos : itb) { double distance = SphericalEarthMath.distance(loc, pos); if(distance < location.getAccuracy() + MAX_DISTANCE_TO_ELEMENT_FOR_SURVEY) return true; } return false; }
@Override public void onLocationChanged(Location location) { float bestAccuracy = -1f; if (location.getAccuracy() != 0.0f && (location.getAccuracy() < bestAccuracy) || bestAccuracy == -1f) { if (location.getAccuracy() < Const.MIN_ACCURACY) { locationManager.removeUpdates(this); } } bestAccuracy = location.getAccuracy(); }
boolean isLocationSufficient(Location location, long acceptableTimePeriod, float acceptableAccuracy) { if (location == null) return false; float givenAccuracy = location.getAccuracy(); long givenTime = location.getTime(); long minAcceptableTime = new Date().getTime() - acceptableTimePeriod; return minAcceptableTime <= givenTime && acceptableAccuracy >= givenAccuracy; } }
private void updateTripStats( final Location newLocation) { final float spdConvert = 2.2369f; // Stats should only be updated if accuracy is decent if (newLocation.getAccuracy() > 20) return; // Speed data is sometimes awful, too: curSpeedMph_ = newLocation.getSpeed() * spdConvert; }
@Override public void onLocationChanged(Location location) { this.myLocationOverlay.setPosition(location.getLatitude(), location.getLongitude(), location.getAccuracy()); // Follow location this.mapView.setCenter(new LatLong(location.getLatitude(), location.getLongitude())); }
private void returnLocation() { if (mLocation != null) { Intent i = new Intent(); i.putExtra( FormEntryActivity.LOCATION_RESULT, mLocation.getLatitude() + " " + mLocation.getLongitude() + " " + mLocation.getAltitude() + " " + mLocation.getAccuracy()); setResult(RESULT_OK, i); } finish(); }
public LocationAssert hasAccuracy(float accuracy) { isNotNull(); float actualAccuracy = actual.getAccuracy(); assertThat(actualAccuracy) // .overridingErrorMessage("Expected accuracy <%s> but was <%s>.", accuracy, actualAccuracy) // .isEqualTo(accuracy); return this; }
public void onLocationChanged(@Nullable Location location) { if(location == null) { Timber.e("no location provided"); return; } Timber.v("location update received: tst:%s, acc:%s, lat:%s, lon:%s",location.getTime(), location.getAccuracy(), location.getLatitude(), location.getLongitude()); if (location.getTime() > locationRepo.getCurrentLocationTime()) { locationProcessor.onLocationChanged(location); } }