Search in sources :

Example 1 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class AudioVideoNotesPlugin method defaultAction.

public void defaultAction(final MapActivity mapActivity) {
    final Location loc = app.getLocationProvider().getLastKnownLocation();
    // double lon = mapActivity.getMapView().getLongitude();
    if (loc == null) {
        Toast.makeText(app, R.string.audionotes_location_not_defined, Toast.LENGTH_LONG).show();
        return;
    }
    double lon = loc.getLongitude();
    double lat = loc.getLatitude();
    int action = AV_DEFAULT_ACTION.get();
    if (action == AV_DEFAULT_ACTION_CHOOSE) {
        chooseDefaultAction(lat, lon, mapActivity);
    } else {
        takeAction(mapActivity, lon, lat, action);
    }
}
Also used : GeoParsedPoint(net.osmand.util.GeoPointParserUtil.GeoParsedPoint) Location(net.osmand.Location)

Example 2 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class RoutingHelper method updateCurrentRouteStatus.

private boolean updateCurrentRouteStatus(Location currentLocation, float posTolerance) {
    List<Location> routeNodes = route.getImmutableAllLocations();
    int currentRoute = route.currentRoute;
    // 1. Try to proceed to next point using orthogonal distance (finding minimum orthogonal dist)
    while (currentRoute + 1 < routeNodes.size()) {
        double dist = currentLocation.distanceTo(routeNodes.get(currentRoute));
        if (currentRoute > 0) {
            dist = getOrthogonalDistance(currentLocation, routeNodes.get(currentRoute - 1), routeNodes.get(currentRoute));
        }
        boolean processed = false;
        // if we are still too far try to proceed many points
        // if not then look ahead only 3 in order to catch sharp turns
        boolean longDistance = dist >= 250;
        int newCurrentRoute = lookAheadFindMinOrthogonalDistance(currentLocation, routeNodes, currentRoute, longDistance ? 15 : 8);
        double newDist = getOrthogonalDistance(currentLocation, routeNodes.get(newCurrentRoute), routeNodes.get(newCurrentRoute + 1));
        if (longDistance) {
            if (newDist < dist) {
                if (log.isDebugEnabled()) {
                    // $NON-NLS-1$//$NON-NLS-2$
                    log.debug("Processed by distance : (new) " + newDist + " (old) " + dist);
                }
                processed = true;
            }
        } else if (newDist < dist || newDist < 10) {
            // newDist < 10 (avoid distance 0 till next turn)
            if (dist > posTolerance) {
                processed = true;
                if (log.isDebugEnabled()) {
                    // $NON-NLS-1$//$NON-NLS-2$
                    log.debug("Processed by distance : " + newDist + " " + dist);
                }
            } else {
                // but you have not yet turned (could be checked bearing)
                if (currentLocation.hasBearing() || lastFixedLocation != null) {
                    float bearingToRoute = currentLocation.bearingTo(routeNodes.get(currentRoute));
                    float bearingRouteNext = routeNodes.get(newCurrentRoute).bearingTo(routeNodes.get(newCurrentRoute + 1));
                    float bearingMotion = currentLocation.hasBearing() ? currentLocation.getBearing() : lastFixedLocation.bearingTo(currentLocation);
                    double diff = Math.abs(MapUtils.degreesDiff(bearingMotion, bearingToRoute));
                    double diffToNext = Math.abs(MapUtils.degreesDiff(bearingMotion, bearingRouteNext));
                    if (diff > diffToNext) {
                        if (log.isDebugEnabled()) {
                            log.debug("Processed point bearing deltas : " + diff + " " + diffToNext);
                        }
                        processed = true;
                    }
                }
            }
        }
        if (processed) {
            // that node already passed
            route.updateCurrentRoute(newCurrentRoute + 1);
            currentRoute = newCurrentRoute + 1;
            app.getNotificationHelper().refreshNotification(NotificationType.NAVIGATION);
        } else {
            break;
        }
    }
    // 2. check if intermediate found
    if (route.getIntermediatePointsToPass() > 0 && route.getDistanceToNextIntermediate(lastFixedLocation) < getArrivalDistance() * 2f && !isRoutePlanningMode) {
        showMessage(app.getString(R.string.arrived_at_intermediate_point));
        route.passIntermediatePoint();
        TargetPointsHelper targets = app.getTargetPointsHelper();
        String name = "";
        if (intermediatePoints != null && !intermediatePoints.isEmpty()) {
            LatLon rm = intermediatePoints.remove(0);
            List<TargetPoint> ll = targets.getIntermediatePointsNavigation();
            int ind = -1;
            for (int i = 0; i < ll.size(); i++) {
                if (ll.get(i).point != null && MapUtils.getDistance(ll.get(i).point, rm) < 5) {
                    name = ll.get(i).getOnlyName();
                    ind = i;
                    break;
                }
            }
            if (ind >= 0) {
                targets.removeWayPoint(false, ind);
            }
        }
        if (isFollowingMode) {
            voiceRouter.arrivedIntermediatePoint(name);
        }
        // double check
        while (intermediatePoints != null && route.getIntermediatePointsToPass() < intermediatePoints.size()) {
            intermediatePoints.remove(0);
        }
    }
    // 3. check if destination found
    Location lastPoint = routeNodes.get(routeNodes.size() - 1);
    if (currentRoute > routeNodes.size() - 3 && currentLocation.distanceTo(lastPoint) < getArrivalDistance() && !isRoutePlanningMode) {
        // showMessage(app.getString(R.string.arrived_at_destination));
        TargetPointsHelper targets = app.getTargetPointsHelper();
        TargetPoint tp = targets.getPointToNavigate();
        String description = tp == null ? "" : tp.getOnlyName();
        if (isFollowingMode) {
            voiceRouter.arrivedDestinationPoint(description);
        }
        boolean onDestinationReached = OsmandPlugin.onDestinationReached();
        onDestinationReached &= app.getAppCustomization().onDestinationReached();
        if (onDestinationReached) {
            clearCurrentRoute(null, null);
            setRoutePlanningMode(false);
            app.runInUIThread(new Runnable() {

                @Override
                public void run() {
                    settings.LAST_ROUTING_APPLICATION_MODE = settings.APPLICATION_MODE.get();
                // settings.APPLICATION_MODE.set(settings.DEFAULT_APPLICATION_MODE.get());
                }
            });
            finishCurrentRoute();
            // targets.clearPointToNavigate(false);
            return true;
        }
    }
    return false;
}
Also used : LatLon(net.osmand.data.LatLon) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) Location(net.osmand.Location)

Example 3 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class RoutingHelper method getCurrentName.

// protected boolean isDistanceLess(float currentSpeed, double dist, double etalon, float defSpeed){
// if(dist < etalon || ((dist / currentSpeed) < (etalon / defSpeed))){
// return true;
// }
// return false;
// }
public synchronized String getCurrentName(TurnType[] next) {
    NextDirectionInfo n = getNextRouteDirectionInfo(new NextDirectionInfo(), true);
    Location l = lastFixedLocation;
    float speed = 0;
    if (l != null && l.hasSpeed()) {
        speed = l.getSpeed();
    }
    if (n.distanceTo > 0 && n.directionInfo != null && !n.directionInfo.getTurnType().isSkipToSpeak() && voiceRouter.isDistanceLess(speed, n.distanceTo, voiceRouter.PREPARE_DISTANCE * 0.75f, 0f)) {
        String nm = n.directionInfo.getStreetName();
        String rf = n.directionInfo.getRef();
        String dn = n.directionInfo.getDestinationName();
        if (next != null) {
            next[0] = n.directionInfo.getTurnType();
        }
        return formatStreetName(nm, rf, dn, "»");
    }
    RouteSegmentResult rs = getCurrentSegmentResult();
    if (rs != null) {
        String nm = rs.getObject().getName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get());
        String rf = rs.getObject().getRef(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rs.isForwardDirection());
        String dn = rs.getObject().getDestinationName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get(), rs.isForwardDirection());
        return formatStreetName(nm, rf, dn, "»");
    }
    return null;
}
Also used : NextDirectionInfo(net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo) RouteSegmentResult(net.osmand.router.RouteSegmentResult) Location(net.osmand.Location)

Example 4 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class RoutingHelper method identifyUTurnIsNeeded.

private boolean identifyUTurnIsNeeded(Location currentLocation, float posTolerance) {
    if (finalLocation == null || currentLocation == null || !route.isCalculated()) {
        return false;
    }
    boolean isOffRoute = false;
    if (currentLocation.hasBearing()) {
        float bearingMotion = currentLocation.getBearing();
        Location nextRoutePosition = route.getNextRouteLocation();
        float bearingToRoute = currentLocation.bearingTo(nextRoutePosition);
        double diff = MapUtils.degreesDiff(bearingMotion, bearingToRoute);
        // This prompt is an interim advice and does only sound if a new route in forward direction could not be found in x seconds
        if (Math.abs(diff) > 135f) {
            float d = currentLocation.distanceTo(nextRoutePosition);
            // 60m tolerance to allow for GPS inaccuracy
            if (d > posTolerance) {
                // require x sec continuous since first detection
                if (deviateFromRouteDetected == 0) {
                    deviateFromRouteDetected = System.currentTimeMillis();
                } else if ((System.currentTimeMillis() - deviateFromRouteDetected > 10000)) {
                    isOffRoute = true;
                // log.info("bearingMotion is opposite to bearingRoute"); //$NON-NLS-1$
                }
            }
        } else {
            deviateFromRouteDetected = 0;
        }
    }
    return isOffRoute;
}
Also used : Location(net.osmand.Location)

Example 5 with Location

use of net.osmand.Location in project Osmand by osmandapp.

the class QuickSearchDialogFragment method updateCompassValue.

@Override
public void updateCompassValue(final float value) {
    // 99 in next line used to one-time initialize arrows (with reference vs. fixed-north direction)
    // on non-compass devices
    float lastHeading = heading != null ? heading : 99;
    heading = value;
    if (Math.abs(MapUtils.degreesDiff(lastHeading, heading)) > 5) {
        final Location location = this.location;
        app.runInUIThread(new Runnable() {

            @Override
            public void run() {
                updateLocationUI(location, value);
            }
        });
    } else {
        heading = lastHeading;
    }
}
Also used : 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