Search in sources :

Example 91 with Location

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);
    }
}
Also used : PointI(net.osmand.core.jni.PointI) Location(net.osmand.Location)

Example 92 with 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();
    }
}
Also used : RouteDataObject(net.osmand.binary.RouteDataObject) Paint(android.graphics.Paint) Location(net.osmand.Location)

Example 93 with Location

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;
}
Also used : LatLon(net.osmand.data.LatLon) RouteDataObject(net.osmand.binary.RouteDataObject) Location(net.osmand.Location)

Example 94 with Location

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);
            }
        }
    });
}
Also used : ValueHolder(net.osmand.ValueHolder) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) WeakReference(java.lang.ref.WeakReference) Iterator(java.util.Iterator) Location(net.osmand.Location)

Example 95 with Location

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;
    }
}
Also used : LatLon(net.osmand.data.LatLon) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) Location(net.osmand.Location)

Aggregations

Location (net.osmand.Location)105 LatLon (net.osmand.data.LatLon)37 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)29 ArrayList (java.util.ArrayList)21 LocationPoint (net.osmand.data.LocationPoint)21 View (android.view.View)13 OsmandApplication (net.osmand.plus.OsmandApplication)12 Paint (android.graphics.Paint)11 TextView (android.widget.TextView)11 ImageView (android.widget.ImageView)10 RouteDataObject (net.osmand.binary.RouteDataObject)9 WptPt (net.osmand.plus.GPXUtilities.WptPt)9 MapMarker (net.osmand.plus.MapMarkersHelper.MapMarker)8 TargetPointsHelper (net.osmand.plus.TargetPointsHelper)7 PointDescription (net.osmand.data.PointDescription)6 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)6 TIntArrayList (gnu.trove.list.array.TIntArrayList)5 IOException (java.io.IOException)5 QuadPoint (net.osmand.data.QuadPoint)5 MapActivity (net.osmand.plus.activities.MapActivity)5