public LocationAssert hasProvider(String name) { isNotNull(); String actualName = actual.getProvider(); assertThat(actualName) // .overridingErrorMessage("Expected provider <%s> but was <%s>.", name, actualName) // .isEqualTo(name); 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; } }
public void simulateLocation(Location location) { cleanupRemovedLocationListeners(); setLastKnownLocation(location.getProvider(), location); List<ListenerRegistration> providerListeners = locationListeners.get( location.getProvider()); if (providerListeners == null) return; for (ListenerRegistration listenerReg : providerListeners) { if(listenerReg.lastSeenLocation != null && location != null) { float distanceChange = distanceBetween(location, listenerReg.lastSeenLocation); boolean withinMinDistance = distanceChange < listenerReg.minDistance; boolean exceededMinTime = location.getTime() - listenerReg.lastSeenTime > listenerReg.minTime; if (withinMinDistance || !exceededMinTime) continue; } listenerReg.lastSeenLocation = copyOf(location); listenerReg.lastSeenTime = location == null ? 0 : location.getTime(); listenerReg.listener.onLocationChanged(copyOf(location)); } cleanupRemovedLocationListeners(); }
currentBestLocation.getProvider());
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); } }
public void onLocationChanged(Location fix) { if(fix.getProvider().equals(LocationManager.GPS_PROVIDER)){ //here Gps } else if(fix.getProvider().equals(LocationManager.NETWORK_PROVIDER)){ //here Network }
@Override public void onLocationChanged(final Location location) { // it Returns the name of the provider that generated this fix. String locationProvider = location.getProvider() }
@Override public void onLocationChanged(Location locationNew) { // for example, check if location was provided by GPS if (locationNew.getProvider().equals(LocationManager.GPS_PROVIDER)) { // do your work here } }
//query provider from Location public void onLocationChanged(Location loc){ String provider = loc.getProvider(); if (provider.equals(LocationManager.GPS_PROVIDER)){ //GPS Location } else if (provider.equals(LocationManager.NETWORK_PROVIDER)){ //Network Location } .... }
/** * Call this after location has changed to refresh status * @param location new location */ public void notifyLocation(Location location) { isGpsLocated = location.getProvider().equals(LocationManager.GPS_PROVIDER); refreshStatus(); }
LocationListner locationListner = new LocationListener(){ public void onLocationChanged(Location location){ String provider = location.getProvider(); } }
private String formatLocation(Location location) { return String.format("provider: %s lat: %s, lon: %s, accuracy: %s", location.getProvider(), location.getLatitude(), location.getLongitude(), location.getAccuracy()); }
public void onLocationChanged(Location location) { currentLatitude = (float) location.getLatitude(); currentLongitude = (float) location.getLongitude(); currentAccuracy = (float) location.getAccuracy(); currentProvider = location.getProvider(); }
@Override public void onLocationChanged(Location gps) { location = gps; // just take the newest location Utils.log("location (" + gps.getProvider() + "): " + location.getLatitude() + " " + location.getLongitude()); }
public LocationAssert hasProvider(String name) { isNotNull(); String actualName = actual.getProvider(); assertThat(actualName) // .overridingErrorMessage("Expected provider <%s> but was <%s>.", name, actualName) // .isEqualTo(name); return this; }
@Override public void onLocationChanged(Location location) { progressDialog.hide(); try { locationManager.removeUpdates(this); } catch (SecurityException e) { Log.e("LocationManager", "Error while trying to stop listening for location updates. This is probably a permissions issue", e); } Log.i("LOCATION (" + location.getProvider().toUpperCase() + ")", location.getLatitude() + ", " + location.getLongitude()); double latitude = location.getLatitude(); double longitude = location.getLongitude(); new ProvideCityNameTask(this, this, progressDialog).execute("coords", Double.toString(latitude), Double.toString(longitude)); }
@Override public void onLocationChanged(final Location location) { // ignore temporary non-gps fix if (mIgnorer.shouldIgnore(location.getProvider(), System.currentTimeMillis())) { return; } mLocation = location; if (mMyLocationConsumer != null) { mMyLocationConsumer.onLocationChanged(mLocation, this); } }
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 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; }