use of net.osmand.Location in project Osmand by osmandapp.
the class MainActivity method updateLocation.
@Override
public void updateLocation(Location location) {
final SampleApplication app = getMyApplication();
final Location lastKnownLocation = app.getLocationProvider().getLastKnownLocation();
if (lastKnownLocation == null || mapView == null) {
app.runInUIThread(new Runnable() {
@Override
public void run() {
if (!myLocationMarker.isHidden()) {
mapView.suspendSymbolsUpdate();
myLocationMarker.setIsHidden(true);
mapView.resumeSymbolsUpdate();
}
}
});
return;
}
final PointI target31 = Utilities.convertLatLonTo31(new net.osmand.core.jni.LatLon(location.getLatitude(), location.getLongitude()));
app.runInUIThread(new Runnable() {
@Override
public void run() {
mapView.suspendSymbolsUpdate();
myLocationMarker.setIsHidden(false);
myLocationMarker.setPosition(target31);
myLocationMarker.setIsAccuracyCircleVisible(true);
myLocationMarker.setAccuracyCircleRadius(lastKnownLocation.getAccuracy());
mapView.resumeSymbolsUpdate();
}
});
if (menu != null) {
menu.updateMyLocation(location);
}
}
use of net.osmand.Location in project Osmand by osmandapp.
the class ImpassableRoadsLayer method collectObjectsFromPoint.
@Override
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> o, boolean unknownLocation) {
if (tileBox.getZoom() >= startZoom) {
int ex = (int) point.x;
int ey = (int) point.y;
int compare = getRadiusPoi(tileBox);
int radius = compare * 3 / 2;
for (RouteDataObject road : getImpassableRoads()) {
Location location = getImpassableRoadLocations().get(road.getId());
if (location != null) {
int x = (int) tileBox.getPixXFromLatLon(location.getLatitude(), location.getLongitude());
int y = (int) tileBox.getPixYFromLatLon(location.getLatitude(), location.getLongitude());
if (calculateBelongs(ex, ey, x, y, compare)) {
compare = radius;
o.add(road);
}
}
}
}
if (!storedRoadDataObjects.isEmpty()) {
activity.getMyApplication().getAvoidSpecificRoads().initPreservedData();
storedRoadDataObjects.clear();
}
}
use of net.osmand.Location in project Osmand by osmandapp.
the class ImpassableRoadsLayer method getObjectLocation.
@Override
public LatLon getObjectLocation(Object o) {
if (o instanceof RouteDataObject) {
RouteDataObject route = (RouteDataObject) o;
Location location = impassableRoadLocations.get(route.getId());
return new LatLon(location.getLatitude(), location.getLongitude());
}
return null;
}
use of net.osmand.Location in project Osmand by osmandapp.
the class RoutingHelper method setNewRoute.
private void setNewRoute(RouteCalculationResult prevRoute, final RouteCalculationResult res, Location start) {
final boolean newRoute = !prevRoute.isCalculated();
if (isFollowingMode) {
if (lastFixedLocation != null) {
start = lastFixedLocation;
}
// try remove false route-recalculated prompts by checking direction to second route node
boolean wrongMovementDirection = false;
List<Location> routeNodes = res.getImmutableAllLocations();
if (routeNodes != null && !routeNodes.isEmpty()) {
int newCurrentRoute = lookAheadFindMinOrthogonalDistance(start, routeNodes, res.currentRoute, 15);
if (newCurrentRoute + 1 < routeNodes.size()) {
// This check is valid for Online/GPX services (offline routing is aware of route direction)
wrongMovementDirection = checkWrongMovementDirection(start, routeNodes.get(newCurrentRoute + 1));
// set/reset evalWaitInterval only if new route is in forward direction
if (wrongMovementDirection) {
evalWaitInterval = 3000;
} else {
evalWaitInterval = Math.max(3000, evalWaitInterval * 3 / 2);
evalWaitInterval = Math.min(evalWaitInterval, 120000);
}
}
}
// If route is in wrong direction after one more setLocation it will be recalculated
if (!wrongMovementDirection || newRoute) {
voiceRouter.newRouteIsCalculated(newRoute);
}
}
app.getWaypointHelper().setNewRoute(res);
app.runInUIThread(new Runnable() {
@Override
public void run() {
ValueHolder<Boolean> showToast = new ValueHolder<Boolean>();
showToast.value = true;
Iterator<WeakReference<IRouteInformationListener>> it = listeners.iterator();
while (it.hasNext()) {
WeakReference<IRouteInformationListener> ref = it.next();
IRouteInformationListener l = ref.get();
if (l == null) {
it.remove();
} else {
l.newRouteIsCalculated(newRoute, showToast);
}
}
if (showToast.value && OsmandPlugin.isDevelopment()) {
String msg = app.getString(R.string.new_route_calculated_dist) + ": " + OsmAndFormatter.getFormattedDistance(res.getWholeDistance(), app);
if (res.getRoutingTime() != 0f) {
msg += " (" + Algorithms.formatDuration((int) res.getRoutingTime(), app.accessibilityEnabled()) + ")";
}
app.showToastMessage(msg);
}
}
});
}
use of net.osmand.Location in project Osmand by osmandapp.
the class RoutingHelper method setCurrentLocation.
private Location setCurrentLocation(Location currentLocation, boolean returnUpdatedLocation, RouteCalculationResult previousRoute, boolean targetPointsChanged) {
Location locationProjection = currentLocation;
if (finalLocation == null || currentLocation == null) {
isDeviatedFromRoute = false;
return locationProjection;
}
float posTolerance = POSITION_TOLERANCE;
if (currentLocation.hasAccuracy()) {
posTolerance = POSITION_TOLERANCE / 2 + currentLocation.getAccuracy();
}
boolean calculateRoute = false;
synchronized (this) {
isDeviatedFromRoute = false;
double distOrth = 0;
// 0. Route empty or needs to be extended? Then re-calculate route.
if (route.isEmpty()) {
calculateRoute = true;
} else {
// 1. Update current route position status according to latest received location
boolean finished = updateCurrentRouteStatus(currentLocation, posTolerance);
if (finished) {
return null;
}
List<Location> routeNodes = route.getImmutableAllLocations();
int currentRoute = route.currentRoute;
// >100m off current route (sideways)
if (currentRoute > 0) {
distOrth = getOrthogonalDistance(currentLocation, routeNodes.get(currentRoute - 1), routeNodes.get(currentRoute));
if ((!settings.DISABLE_OFFROUTE_RECALC.get()) && (distOrth > (1.7 * posTolerance))) {
// $NON-NLS-1$
log.info("Recalculate route, because correlation : " + distOrth);
isDeviatedFromRoute = true;
calculateRoute = true;
}
}
// 3. Identify wrong movement direction
Location next = route.getNextRouteLocation();
boolean wrongMovementDirection = checkWrongMovementDirection(currentLocation, next);
if ((!settings.DISABLE_WRONG_DIRECTION_RECALC.get()) && wrongMovementDirection && (currentLocation.distanceTo(routeNodes.get(currentRoute)) > (2 * posTolerance))) {
// $NON-NLS-1$
log.info("Recalculate route, because wrong movement direction: " + currentLocation.distanceTo(routeNodes.get(currentRoute)));
isDeviatedFromRoute = true;
calculateRoute = true;
}
// 4. Identify if UTurn is needed
if (identifyUTurnIsNeeded(currentLocation, posTolerance)) {
isDeviatedFromRoute = true;
}
// Do not update in route planning mode
if (isFollowingMode) {
boolean inRecalc = calculateRoute || isRouteBeingCalculated();
if (!inRecalc && !wrongMovementDirection) {
voiceRouter.updateStatus(currentLocation, false);
voiceRouterStopped = false;
} else if (isDeviatedFromRoute && !voiceRouterStopped) {
voiceRouter.interruptRouteCommands();
// Prevents excessive execution of stop() code
voiceRouterStopped = true;
}
if (distOrth > 350) {
voiceRouter.announceOffRoute(distOrth);
}
}
// calculate projection of current location
if (currentRoute > 0) {
locationProjection = new Location(currentLocation);
Location nextLocation = routeNodes.get(currentRoute);
LatLon project = getProject(currentLocation, routeNodes.get(currentRoute - 1), routeNodes.get(currentRoute));
locationProjection.setLatitude(project.getLatitude());
locationProjection.setLongitude(project.getLongitude());
// we need to update bearing too
float bearingTo = locationProjection.bearingTo(nextLocation);
locationProjection.setBearing(bearingTo);
}
}
lastFixedLocation = currentLocation;
lastProjection = locationProjection;
}
if (calculateRoute) {
recalculateRouteInBackground(currentLocation, finalLocation, intermediatePoints, currentGPXRoute, previousRoute.isCalculated() ? previousRoute : null, false, !targetPointsChanged);
} else {
Thread job = currentRunningJob;
if (job instanceof RouteRecalculationThread) {
RouteRecalculationThread thread = (RouteRecalculationThread) job;
if (!thread.isParamsChanged()) {
thread.stopCalculation();
}
if (isFollowingMode) {
voiceRouter.announceBackOnRoute();
}
}
}
double projectDist = mode != null && mode.hasFastSpeed() ? posTolerance : posTolerance / 2;
if (returnUpdatedLocation && locationProjection != null && currentLocation.distanceTo(locationProjection) < projectDist) {
return locationProjection;
} else {
return currentLocation;
}
}
Aggregations