diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java index b89a3c2064..78342c607e 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java @@ -46,7 +46,7 @@ public class OsmAndLocationProvider implements SensorEventListener { public static final int REQUEST_LOCATION_PERMISSION = 100; - private static final String SIMULATED_PROVIDER = "OsmAnd"; + public static final String SIMULATED_PROVIDER = "OsmAnd"; public interface OsmAndLocationListener { diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationSimulation.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationSimulation.java index 5034b7d81c..21987300de 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndLocationSimulation.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationSimulation.java @@ -120,9 +120,13 @@ public class OsmAndLocationSimulation { @Override public void run() { Location current = directions.isEmpty() ? null : new Location(directions.remove(0)); + Location prev = current; long prevTime = current == null ? 0 : current.getTime(); float meters = metersToGoInFiveSteps(directions, current); + if(current != null) { + current.setProvider(OsmAndLocationProvider.SIMULATED_PROVIDER); + } while (!directions.isEmpty() && routeAnimation != null) { int timeout = (int) (time * 1000); float intervalTime = time; diff --git a/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java b/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java index 1d8bf922f8..f2f09745ed 100644 --- a/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java +++ b/OsmAnd/src/net/osmand/plus/monitoring/LiveMonitoringHelper.java @@ -1,6 +1,5 @@ package net.osmand.plus.monitoring; -import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; @@ -11,16 +10,17 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; -import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLSession; import net.osmand.PlatformUtil; +import net.osmand.data.LatLon; import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; -import net.osmand.plus.R; +import net.osmand.util.MapUtils; import org.apache.commons.logging.Log; @@ -32,6 +32,7 @@ public class LiveMonitoringHelper { protected Context ctx; private OsmandSettings settings; private long lastTimeUpdated; + private LatLon lastPoint; private final static Log log = PlatformUtil.getLog(LiveMonitoringHelper.class); public LiveMonitoringHelper(Context ctx){ @@ -44,18 +45,35 @@ public class LiveMonitoringHelper { } public void updateLocation(net.osmand.Location location) { + boolean record = false; + long locationTime = System.currentTimeMillis(); if (OsmAndLocationProvider.isPointAccurateForRouting(location) && isLiveMonitoringEnabled() && OsmAndLocationProvider.isNotSimulatedLocation(location) && OsmandPlugin.getEnabledPlugin(OsmandMonitoringPlugin.class) != null) { - long locationTime = System.currentTimeMillis(); if (locationTime - lastTimeUpdated > settings.LIVE_MONITORING_INTERVAL.get()) { - LiveMonitoringData data = new LiveMonitoringData((float)location.getLatitude(), (float)location.getLongitude(), - (float)location.getAltitude(), location.getSpeed(), location.getAccuracy(), location.getBearing(), locationTime); - new LiveSender().execute(data); - lastTimeUpdated = locationTime; + record = true; + } + float minDistance = settings.SAVE_TRACK_MIN_DISTANCE.get(); + if(minDistance > 0 && lastPoint != null && MapUtils.getDistance(lastPoint, location.getLatitude(), location.getLongitude()) < + minDistance) { + record = false; + } + float precision = settings.SAVE_TRACK_PRECISION.get(); + if(precision > 0 && (!location.hasAccuracy() || location.getAccuracy() > precision)) { + record = false; + } + float minSpeed = settings.SAVE_TRACK_MIN_SPEED.get(); + if(minSpeed > 0 && (!location.hasSpeed() || location.getSpeed() < minSpeed)) { + record = false; } } - + if(record) { + LiveMonitoringData data = new LiveMonitoringData((float)location.getLatitude(), (float)location.getLongitude(), + (float)location.getAltitude(), location.getSpeed(), location.getAccuracy(), location.getBearing(), locationTime); + new LiveSender().execute(data); + lastPoint = new LatLon(location.getLatitude(), location.getLongitude()); + lastTimeUpdated = locationTime; + } }