Commit 2f32efdc authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

LocationUpdates: only trigger onLocationChanged, if the location

actually changed.
parent 29ba1deb
......@@ -319,6 +319,8 @@ public class DefaultTopologyComponent implements TopologyComponent {
private long interval = 1 * Simulator.MINUTE_UNIT;
private int priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY;
private Location lastLocation = null;
private List<LocationListener> listeners = new LinkedList<LocationListener>();
......@@ -359,7 +361,11 @@ public class DefaultTopologyComponent implements TopologyComponent {
public void eventOccurred(Object content, int type) {
if (!listeners.isEmpty()) {
// Only reschedule, if at least one listener is ... listening
listeners.forEach((LocationListener listener) -> listener.onLocationChanged(getLastLocation()));
Location newLoc = getLastLocation();
if (lastLocation == null || lastLocation.distanceTo(newLoc) > 0) {
listeners.forEach((LocationListener listener) -> listener.onLocationChanged(newLoc));
lastLocation = newLoc;
}
Event.scheduleWithDelay(interval, this, null, 0);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment