List of usage examples for android.location Location isFromMockProvider
public boolean isFromMockProvider()
From source file:de.ncoder.sensorsystem.android.logging.JSONUtils.java
private static Object wrapLocation(Location loc) { try {// www. ja va2 s. com JSONObject json = new JSONObject(); json.put("provider", loc.getProvider()); json.put("latitude", loc.getLatitude()); json.put("longitude", loc.getLongitude()); if (loc.hasAccuracy()) json.put("accuracy", loc.getAccuracy()); json.put("time", loc.getTime()); if (loc.hasAltitude()) json.put("alt", loc.getAltitude()); if (loc.hasSpeed()) json.put("vel", loc.getSpeed()); if (loc.hasBearing()) json.put("bear", loc.getBearing()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) if (loc.isFromMockProvider()) json.put("mock", true); if (loc.getExtras() != null) { json.put("extra", wrap(loc.getExtras())); } return json; } catch (JSONException e) { return loc.toString() + " threw " + e.toString(); } }
From source file:com.facebook.react.modules.location.LocationModule.java
private static WritableMap locationToMap(Location location) { WritableMap map = Arguments.createMap(); WritableMap coords = Arguments.createMap(); coords.putDouble("latitude", location.getLatitude()); coords.putDouble("longitude", location.getLongitude()); coords.putDouble("altitude", location.getAltitude()); coords.putDouble("accuracy", location.getAccuracy()); coords.putDouble("heading", location.getBearing()); coords.putDouble("speed", location.getSpeed()); map.putMap("coords", coords); map.putDouble("timestamp", location.getTime()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { map.putBoolean("mocked", location.isFromMockProvider()); }/*from w ww . ja v a2 s.c o m*/ return map; }
From source file:com.klaasnotfound.locationassistant.LocationAssistant.java
private boolean isLocationPlausible(Location location) { if (location == null) return false; boolean isMock = mockLocationsEnabled || (Build.VERSION.SDK_INT >= 18 && location.isFromMockProvider()); if (isMock) { lastMockLocation = location;/*w ww . j a v a 2s . co m*/ numGoodReadings = 0; } else numGoodReadings = Math.min(numGoodReadings + 1, 1000000); // Prevent overflow // We only clear that incident record after a significant show of good behavior if (numGoodReadings >= 20) lastMockLocation = null; // If there's nothing to compare against, we have to trust it if (lastMockLocation == null) return true; // And finally, if it's more than 1km away from the last known mock, we'll trust it double d = location.distanceTo(lastMockLocation); return (d > 1000); }