Enable stickin mode for 15 meters
This commit is contained in:
parent
f45bbfe70d
commit
fff6be1a17
3 changed files with 30 additions and 11 deletions
|
@ -57,6 +57,10 @@ public class MapUtils {
|
|||
}
|
||||
|
||||
public static double getOrthogonalDistance(double lat, double lon, double fromLat, double fromLon, double toLat, double toLon) {
|
||||
return getDistance(getProjection(lat, lon, fromLat, fromLon, toLat, toLon), lat, lon);
|
||||
}
|
||||
|
||||
public static LatLon getProjection(double lat, double lon, double fromLat, double fromLon, double toLat, double toLon) {
|
||||
// not very accurate computation on sphere but for distances < 1000m it is ok
|
||||
double mDist = (fromLat - toLat) * (fromLat - toLat) + (fromLon - toLon) * (fromLon - toLon);
|
||||
double projection = scalarMultiplication(fromLat, fromLon, toLat, toLon, lat, lon);
|
||||
|
@ -72,7 +76,7 @@ public class MapUtils {
|
|||
prlat = fromLat + (toLat - fromLat) * (projection / mDist);
|
||||
prlon = fromLon + (toLon - fromLon) * (projection / mDist);
|
||||
}
|
||||
return getDistance(lat, lon, prlat, prlon);
|
||||
return new LatLon(prlat, prlon);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -737,7 +737,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
|
|||
}
|
||||
}
|
||||
|
||||
public void setLocation(final Location location){
|
||||
public void setLocation( Location location){
|
||||
if(Log.isLoggable(LogUtil.TAG, Log.DEBUG)){
|
||||
Log.d(LogUtil.TAG, "Location changed " + location.getProvider()); //$NON-NLS-1$
|
||||
}
|
||||
|
@ -764,18 +764,17 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
|
|||
|
||||
registerUnregisterSensor(location);
|
||||
|
||||
mapLayers.getLocationLayer().setLastKnownLocation(location);
|
||||
navigationInfo.setLocation(location);
|
||||
if(routingHelper.isFollowingMode()){
|
||||
if(location == null || !location.hasAccuracy() || location.getAccuracy() < ACCURACY_FOR_GPX_AND_ROUTING) {
|
||||
// Update routing position
|
||||
routingHelper.setCurrentLocation(location);
|
||||
// Update routing position and get location for sticking mode
|
||||
Location updatedLocation = routingHelper.setCurrentLocation(location);
|
||||
location = updatedLocation;
|
||||
// Check with delay that gps location is not lost
|
||||
if(location != null && routingHelper.getLeftDistance() > 0){
|
||||
final long fixTime = location.getTime();
|
||||
Message msg = Message.obtain(uiHandler, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
long fixTime = location.getTime();
|
||||
Location lastKnown = getLastKnownLocation();
|
||||
if(lastKnown != null && lastKnown.getTime() - fixTime < LOST_LOCATION_CHECK_DELAY) {
|
||||
// false positive case, still strange how we got here with removeMessages
|
||||
|
@ -792,6 +791,8 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
|
|||
}
|
||||
}
|
||||
}
|
||||
mapLayers.getLocationLayer().setLastKnownLocation(location);
|
||||
navigationInfo.setLocation(location);
|
||||
|
||||
if (location != null) {
|
||||
if (isMapLinkedToLocation()) {
|
||||
|
|
|
@ -171,14 +171,15 @@ public class RoutingHelper {
|
|||
}
|
||||
|
||||
|
||||
public void setCurrentLocation(Location currentLocation) {
|
||||
public Location setCurrentLocation(Location currentLocation) {
|
||||
if (finalLocation == null || currentLocation == null) {
|
||||
makeUturnWhenPossible = false;
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean calculateRoute = false;
|
||||
synchronized (this) {
|
||||
Location locationProjection = currentLocation;
|
||||
// 0. Route empty or needs to be extended? Then re-calculate route.
|
||||
if(route.isEmpty()) {
|
||||
calculateRoute = true;
|
||||
|
@ -186,7 +187,7 @@ public class RoutingHelper {
|
|||
// 1. Update current route position status according to latest received location
|
||||
boolean finished = updateCurrentRouteStatus(currentLocation);
|
||||
if (finished) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
List<Location> routeNodes = route.locations;
|
||||
int currentRoute = route.currentRoute;
|
||||
|
@ -199,6 +200,12 @@ public class RoutingHelper {
|
|||
log.info("Recalculate route, because correlation : " + dist); //$NON-NLS-1$
|
||||
calculateRoute = true;
|
||||
}
|
||||
if(dist < POSITION_TOLERANCE / 2) {
|
||||
LatLon project = getProject(currentLocation, routeNodes.get(currentRoute - 1), routeNodes.get(currentRoute));
|
||||
// calculate projection of current location
|
||||
locationProjection.setLatitude(project.getLatitude());
|
||||
locationProjection.setLongitude(project.getLongitude());
|
||||
}
|
||||
}
|
||||
// 3. Identify wrong movement direction (very similar to 2?)
|
||||
// Put 3*POSITION_TOLERANCE/2 in order to avoid sharp turns
|
||||
|
@ -215,12 +222,13 @@ public class RoutingHelper {
|
|||
voiceRouter.updateStatus(currentLocation, uTurnIsNeeded);
|
||||
}
|
||||
}
|
||||
lastFixedLocation = currentLocation;
|
||||
lastFixedLocation = locationProjection;
|
||||
}
|
||||
|
||||
if (calculateRoute) {
|
||||
recalculateRouteInBackground(lastFixedLocation, finalLocation, currentGPXRoute);
|
||||
}
|
||||
return lastFixedLocation;
|
||||
}
|
||||
|
||||
private double getOrthogonalDistance(Location loc, Location from, Location to) {
|
||||
|
@ -229,6 +237,12 @@ public class RoutingHelper {
|
|||
to.getLatitude(), to.getLongitude());
|
||||
}
|
||||
|
||||
private LatLon getProject(Location loc, Location from, Location to) {
|
||||
return MapUtils.getProjection(loc.getLatitude(),
|
||||
loc.getLongitude(), from.getLatitude(), from.getLongitude(),
|
||||
to.getLatitude(), to.getLongitude());
|
||||
}
|
||||
|
||||
private int lookAheadFindMinOrthogonalDistance(Location currentLocation, List<Location> routeNodes, int currentRoute, int iterations) {
|
||||
double newDist;
|
||||
double dist = Double.POSITIVE_INFINITY;
|
||||
|
|
Loading…
Reference in a new issue