Search in sources :

Example 61 with Location

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

the class RoutePreferencesMenu method updateGpxRoutingParameter.

private void updateGpxRoutingParameter(OtherLocalRoutingParameter gpxParam) {
    RouteProvider.GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute();
    boolean selected = gpxParam.isSelected(settings);
    if (rp != null) {
        if (gpxParam.id == R.string.gpx_option_reverse_route) {
            rp.setReverse(selected);
            TargetPointsHelper tg = app.getTargetPointsHelper();
            List<Location> ps = rp.getPoints();
            if (ps.size() > 0) {
                Location first = ps.get(0);
                Location end = ps.get(ps.size() - 1);
                TargetPointsHelper.TargetPoint pn = tg.getPointToNavigate();
                boolean update = false;
                if (pn == null || MapUtils.getDistance(pn.point, new LatLon(first.getLatitude(), first.getLongitude())) < 10) {
                    tg.navigateToPoint(new LatLon(end.getLatitude(), end.getLongitude()), false, -1);
                    update = true;
                }
                if (tg.getPointToStart() == null || MapUtils.getDistance(tg.getPointToStart().point, new LatLon(end.getLatitude(), end.getLongitude())) < 10) {
                    tg.setStartPoint(new LatLon(first.getLatitude(), first.getLongitude()), false, null);
                    update = true;
                }
                if (update) {
                    tg.updateRouteAndRefresh(true);
                }
            }
        } else if (gpxParam.id == R.string.gpx_option_calculate_first_last_segment) {
            rp.setCalculateOsmAndRouteParts(selected);
            settings.GPX_ROUTE_CALC_OSMAND_PARTS.set(selected);
        } else if (gpxParam.id == R.string.gpx_option_from_start_point) {
            rp.setPassWholeRoute(selected);
        } else if (gpxParam.id == R.string.use_points_as_intermediates) {
            settings.GPX_CALCULATE_RTEPT.set(selected);
            rp.setUseIntermediatePointsRTE(selected);
        } else if (gpxParam.id == R.string.calculate_osmand_route_gpx) {
            settings.GPX_ROUTE_CALC.set(selected);
            rp.setCalculateOsmAndRoute(selected);
            updateParameters();
        }
    }
    if (gpxParam.id == R.string.calculate_osmand_route_without_internet) {
        settings.GPX_ROUTE_CALC_OSMAND_PARTS.set(selected);
    }
    if (gpxParam.id == R.string.fast_route_mode) {
        settings.FAST_ROUTE_MODE.set(selected);
    }
    if (gpxParam.id == R.string.speak_favorites) {
        settings.ANNOUNCE_NEARBY_FAVORITES.set(selected);
    }
}
Also used : LatLon(net.osmand.data.LatLon) RouteProvider(net.osmand.plus.routing.RouteProvider) TargetPointsHelper(net.osmand.plus.TargetPointsHelper) Location(net.osmand.Location)

Example 62 with Location

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

the class AvoidSpecificRoads method addImpassableRoad.

public void addImpassableRoad(@Nullable final MapActivity activity, @NonNull final LatLon loc, final boolean showDialog, @Nullable final AvoidSpecificRoadsCallback callback, final boolean skipWritingSettings) {
    final Location ll = new Location("");
    ll.setLatitude(loc.getLatitude());
    ll.setLongitude(loc.getLongitude());
    ApplicationMode appMode = app.getRoutingHelper().getAppMode();
    app.getLocationProvider().getRouteSegment(ll, appMode, new ResultMatcher<RouteDataObject>() {

        @Override
        public boolean publish(RouteDataObject object) {
            if (object == null) {
                if (activity != null) {
                    Toast.makeText(activity, R.string.error_avoid_specific_road, Toast.LENGTH_LONG).show();
                }
                if (callback != null) {
                    callback.onAddImpassableRoad(false, null);
                }
            } else {
                addImpassableRoadInternal(object, ll, showDialog, activity, loc);
                if (callback != null) {
                    callback.onAddImpassableRoad(true, object);
                }
            }
            return true;
        }

        @Override
        public boolean isCancelled() {
            return callback != null && callback.isCancelled();
        }
    });
    if (!skipWritingSettings) {
        app.getSettings().addImpassableRoad(loc.getLatitude(), loc.getLongitude());
    }
}
Also used : RouteDataObject(net.osmand.binary.RouteDataObject) ApplicationMode(net.osmand.plus.ApplicationMode) Location(net.osmand.Location)

Example 63 with Location

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

the class AvoidSpecificRoads method replaceImpassableRoad.

public void replaceImpassableRoad(final MapActivity activity, final RouteDataObject currentObject, final LatLon loc, final boolean showDialog, final AvoidSpecificRoadsCallback callback) {
    LatLon latLon = getLocation(currentObject);
    app.getSettings().moveImpassableRoad(latLon, loc);
    final Location ll = new Location("");
    ll.setLatitude(loc.getLatitude());
    ll.setLongitude(loc.getLongitude());
    ApplicationMode appMode = app.getRoutingHelper().getAppMode();
    app.getLocationProvider().getRouteSegment(ll, appMode, new ResultMatcher<RouteDataObject>() {

        @Override
        public boolean publish(RouteDataObject object) {
            if (object == null) {
                Toast.makeText(activity, R.string.error_avoid_specific_road, Toast.LENGTH_LONG).show();
                if (callback != null) {
                    callback.onAddImpassableRoad(false, null);
                }
            } else {
                app.getDefaultRoutingConfig().removeImpassableRoad(currentObject);
                addImpassableRoadInternal(object, ll, showDialog, activity, loc);
                if (callback != null) {
                    callback.onAddImpassableRoad(true, object);
                }
            }
            return true;
        }

        @Override
        public boolean isCancelled() {
            return callback != null && callback.isCancelled();
        }
    });
}
Also used : LatLon(net.osmand.data.LatLon) RouteDataObject(net.osmand.binary.RouteDataObject) ApplicationMode(net.osmand.plus.ApplicationMode) Location(net.osmand.Location)

Example 64 with Location

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

the class WaypointHelper method announceVisibleLocations.

public void announceVisibleLocations() {
    Location lastKnownLocation = app.getRoutingHelper().getLastProjection();
    if (lastKnownLocation != null && app.getRoutingHelper().isFollowingMode()) {
        for (int type = 0; type < locationPoints.size(); type++) {
            int currentRoute = route.getCurrentRoute();
            List<LocationPointWrapper> approachPoints = new ArrayList<LocationPointWrapper>();
            List<LocationPointWrapper> announcePoints = new ArrayList<LocationPointWrapper>();
            List<LocationPointWrapper> lp = locationPoints.get(type);
            if (lp != null) {
                int kIterator = pointsProgress.get(type);
                while (kIterator < lp.size() && lp.get(kIterator).routeIndex < currentRoute) {
                    if (type == ALARMS) {
                        AlarmInfo alarm = (AlarmInfo) lp.get(kIterator).getPoint();
                        if (alarm.getLastLocationIndex() >= currentRoute) {
                            break;
                        }
                    }
                    kIterator++;
                }
                pointsProgress.set(type, kIterator);
                while (kIterator < lp.size()) {
                    LocationPointWrapper lwp = lp.get(kIterator);
                    if (type == ALARMS && lwp.routeIndex < currentRoute) {
                        kIterator++;
                        continue;
                    }
                    if (lwp.announce) {
                        if (route.getDistanceToPoint(lwp.routeIndex) > LONG_ANNOUNCE_RADIUS * 2) {
                            break;
                        }
                        LocationPoint point = lwp.point;
                        double d1 = Math.max(0.0, MapUtils.getDistance(lastKnownLocation.getLatitude(), lastKnownLocation.getLongitude(), point.getLatitude(), point.getLongitude()) - lwp.getDeviationDistance());
                        Integer state = locationPointsStates.get(point);
                        if (state != null && state.intValue() == ANNOUNCED_ONCE && getVoiceRouter().isDistanceLess(lastKnownLocation.getSpeed(), d1, SHORT_ANNOUNCE_RADIUS, 0f)) {
                            locationPointsStates.put(point, ANNOUNCED_DONE);
                            announcePoints.add(lwp);
                        } else if (type != ALARMS && (state == null || state == NOT_ANNOUNCED) && getVoiceRouter().isDistanceLess(lastKnownLocation.getSpeed(), d1, LONG_ANNOUNCE_RADIUS, 0f)) {
                            locationPointsStates.put(point, ANNOUNCED_ONCE);
                            approachPoints.add(lwp);
                        } else if (type == ALARMS && (state == null || state == NOT_ANNOUNCED) && getVoiceRouter().isDistanceLess(lastKnownLocation.getSpeed(), d1, ALARMS_ANNOUNCE_RADIUS, 0f)) {
                            locationPointsStates.put(point, ANNOUNCED_ONCE);
                            approachPoints.add(lwp);
                        }
                    }
                    kIterator++;
                }
                if (!announcePoints.isEmpty()) {
                    if (announcePoints.size() > ANNOUNCE_POI_LIMIT) {
                        announcePoints = announcePoints.subList(0, ANNOUNCE_POI_LIMIT);
                    }
                    if (type == WAYPOINTS) {
                        getVoiceRouter().announceWaypoint(announcePoints);
                    } else if (type == POI) {
                        getVoiceRouter().announcePoi(announcePoints);
                    } else if (type == ALARMS) {
                    // nothing to announce
                    } else if (type == FAVORITES) {
                        getVoiceRouter().announceFavorite(announcePoints);
                    }
                }
                if (!approachPoints.isEmpty()) {
                    if (approachPoints.size() > APPROACH_POI_LIMIT) {
                        approachPoints = approachPoints.subList(0, APPROACH_POI_LIMIT);
                    }
                    if (type == WAYPOINTS) {
                        getVoiceRouter().approachWaypoint(lastKnownLocation, approachPoints);
                    } else if (type == POI) {
                        getVoiceRouter().approachPoi(lastKnownLocation, approachPoints);
                    } else if (type == ALARMS) {
                        EnumSet<AlarmInfoType> ait = EnumSet.noneOf(AlarmInfoType.class);
                        for (LocationPointWrapper pw : approachPoints) {
                            ait.add(((AlarmInfo) pw.point).getType());
                        }
                        for (AlarmInfoType t : ait) {
                            app.getRoutingHelper().getVoiceRouter().announceAlarm(new AlarmInfo(t, -1), lastKnownLocation.getSpeed());
                        }
                    } else if (type == FAVORITES) {
                        getVoiceRouter().approachFavorite(lastKnownLocation, approachPoints);
                    }
                }
            }
        }
    }
}
Also used : AlarmInfoType(net.osmand.plus.routing.AlarmInfo.AlarmInfoType) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) LocationPoint(net.osmand.data.LocationPoint) AlarmInfo(net.osmand.plus.routing.AlarmInfo) AmenityRoutePoint(net.osmand.data.Amenity.AmenityRoutePoint) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) Location(net.osmand.Location)

Example 65 with Location

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

the class WaypointHelper method findLocationPoints.

private void findLocationPoints(RouteCalculationResult rt, int type, List<LocationPointWrapper> locationPoints, List<? extends LocationPoint> points, boolean announce) {
    List<Location> immutableAllLocations = rt.getImmutableAllLocations();
    int[] ind = new int[1];
    boolean[] devDirRight = new boolean[1];
    for (LocationPoint p : points) {
        float dist = dist(p, immutableAllLocations, ind, devDirRight);
        int rad = getSearchDeviationRadius(type);
        if (dist <= rad) {
            LocationPointWrapper lpw = new LocationPointWrapper(rt, type, p, dist, ind[0]);
            lpw.deviationDirectionRight = devDirRight[0];
            lpw.setAnnounce(announce);
            locationPoints.add(lpw);
        }
    }
}
Also used : LocationPoint(net.osmand.data.LocationPoint) AmenityRoutePoint(net.osmand.data.Amenity.AmenityRoutePoint) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) 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