@Override protected Location update() { Location location = LocationHelper.create("second-sample", 13, 13, (System.currentTimeMillis() / 1000) % 100); Log.d(TAG, "I was asked for location and I answer: " + location); return location; } }
public static Location average(String source, Collection<Location> locations) { return weightedAverage(source, locations, LocationBalance.BALANCED, new Bundle()); }
@Override protected Location update() { if (System.currentTimeMillis() % 60000 > 2000) { Log.d(TAG, "I decided not to answer now..."); return null; } Location location = LocationHelper.create("sample", 42, 42, 42); Log.d(TAG, "I was asked for location and I answer: " + location); return location; } }
private Location combine(Set<Location> locations) { float minSignal = Integer.MAX_VALUE, maxSignal = Integer.MIN_VALUE; long verified = -1; for (Location location : locations) { minSignal = Math.min(minSignal, getSignalLevel(location)); maxSignal = Math.max(maxSignal, getSignalLevel(location)); if (location.getExtras().containsKey(LocationRetriever.EXTRA_VERIFIED_TIME)) { verified = Math.max(verified, location.getExtras().getLong(LocationRetriever.EXTRA_VERIFIED_TIME)); } } final float finalMaxSignal = maxSignal; final float finalMinSignal = minSignal; Bundle extras = new Bundle(); extras.putInt("COMBINED_OF", locations.size()); if (verified != -1) { extras.putLong(LocationRetriever.EXTRA_VERIFIED_TIME, verified); } return LocationHelper.weightedAverage(provider, locations, new LocationHelper.LocationBalance() { @Override public double getWeight(Location location) { double weight = calculateWeight(location, finalMinSignal, finalMaxSignal); Log.d(TAG, String.format("Using with weight=%f mac=%s sig=%d acc=%f lat=%f lon=%f", weight, location.getExtras().getString(LocationRetriever.EXTRA_MAC_ADDRESS), location.getExtras().getInt(LocationRetriever.EXTRA_SIGNAL_LEVEL), location.getAccuracy(), location.getLatitude(), location.getLongitude())); return weight; } }, extras); }
public static Location create(String source, double latitude, double longitude, double altitude, float accuracy) { Location location = create(source, latitude, longitude, accuracy); location.setAltitude(altitude); return location; }
public static Location create(String source, long time) { Location location = create(source); location.setTime(time); return location; }
public static Location create(String source, long time, Bundle extras) { Location location = create(source, time); location.setExtras(extras); return location; }
public static Location create(String source, double latitude, double longitude, float altitude, Bundle extras) { Location location = create(source, latitude, longitude, altitude); location.setExtras(extras); return location; }
public static Location create(String source, double latitude, double longitude, double altitude, float accuracy, Bundle extras) { Location location = create(source, latitude, longitude, altitude, accuracy); location.setExtras(extras); return location; }
@Override public void run() { synchronized (regular) { while (!regular.isInterrupted()) { try { regular.wait(60000); } catch (InterruptedException e) { return; } Location location = LocationHelper.create("random", random.nextDouble() * 90, random.nextDouble() * 90, random.nextFloat() * 90); Log.d(TAG, "Just reported: " + location); report(location); } } } });
@Override public synchronized void resultCallback(Location locationResult) { if (locationResult == null) { if (lastResponse == null) { // There isn't even a lastResponse to work with Log.d(TAG, "No previous location to replay"); return; } locationResult = LocationHelper.create(PROVIDER, lastResponse.getLatitude(), lastResponse.getLongitude(), lastResponse.getAccuracy()); Log.d(TAG, "Replaying location " + locationResult); } else { lastRequestTime = System.currentTimeMillis(); lastResponse = locationResult; } report(locationResult); }
public static Location create(String source, double latitude, double longitude, float accuracy) { Location location = create(source); location.setLatitude(latitude); location.setLongitude(longitude); location.setAccuracy(accuracy); return location; }
double lon = responseJson.getJSONObject("location").getDouble("lng"); double acc = responseJson.getDouble("accuracy"); response = LocationHelper.create(PROVIDER, lat, lon, (float) acc); this.callback.resultCallback(response); } catch (IOException | JSONException e) {
rslt = LocationHelper.create(source, latitude, longitude, (float) accuracy, extras);
Bundle extras = new Bundle(); extras.putString(LocationRetriever.EXTRA_MAC_ADDRESS, mac); editor.put(LocationHelper.create("unknown", System.currentTimeMillis(), extras)); toRetrieve.remove(mac);