Search in sources :

Example 86 with Location

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

the class RouteProvider method insertInitialSegment.

public void insertInitialSegment(RouteCalculationParams routeParams, List<Location> points, List<RouteDirectionInfo> directions, boolean calculateOsmAndRouteParts) {
    Location realStart = routeParams.start;
    if (realStart != null && points.size() > 0 && realStart.distanceTo(points.get(0)) > 60) {
        Location trackStart = points.get(0);
        RouteCalculationResult newRes = null;
        if (calculateOsmAndRouteParts) {
            LatLon end = new LatLon(trackStart.getLatitude(), trackStart.getLongitude());
            newRes = findOfflineRouteSegment(routeParams, realStart, end);
        }
        List<Location> loct;
        List<RouteDirectionInfo> dt;
        if (newRes != null && newRes.isCalculated()) {
            loct = newRes.getImmutableAllLocations();
            dt = newRes.getImmutableAllDirections();
        } else {
            loct = new ArrayList<Location>();
            loct.add(realStart);
            dt = new ArrayList<RouteDirectionInfo>();
        }
        points.addAll(0, loct);
        directions.addAll(0, dt);
        for (int i = dt.size(); i < directions.size(); i++) {
            directions.get(i).routePointOffset += loct.size();
        }
    }
}
Also used : LatLon(net.osmand.data.LatLon) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) LocationPoint(net.osmand.data.LocationPoint) Location(net.osmand.Location)

Example 87 with Location

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

the class MapInfoWidgetsFactory method createRulerControl.

public TextInfoWidget createRulerControl(final MapActivity map) {
    final String title = "—";
    final TextInfoWidget rulerControl = new TextInfoWidget(map) {

        RulerControlLayer rulerLayer = map.getMapLayers().getRulerControlLayer();

        LatLon cacheFirstTouchPoint = new LatLon(0, 0);

        LatLon cacheSecondTouchPoint = new LatLon(0, 0);

        LatLon cacheSingleTouchPoint = new LatLon(0, 0);

        boolean fingerAndLocDistWasShown;

        @Override
        public boolean updateInfo(DrawSettings drawSettings) {
            OsmandMapTileView view = map.getMapView();
            Location currentLoc = map.getMyApplication().getLocationProvider().getLastKnownLocation();
            if (rulerLayer.isShowDistBetweenFingerAndLocation() && currentLoc != null) {
                if (!cacheSingleTouchPoint.equals(rulerLayer.getTouchPointLatLon())) {
                    cacheSingleTouchPoint = rulerLayer.getTouchPointLatLon();
                    setDistanceText(cacheSingleTouchPoint.getLatitude(), cacheSingleTouchPoint.getLongitude(), currentLoc.getLatitude(), currentLoc.getLongitude());
                    fingerAndLocDistWasShown = true;
                }
            } else if (rulerLayer.isShowTwoFingersDistance()) {
                if (!cacheFirstTouchPoint.equals(view.getFirstTouchPointLatLon()) || !cacheSecondTouchPoint.equals(view.getSecondTouchPointLatLon()) || fingerAndLocDistWasShown) {
                    cacheFirstTouchPoint = view.getFirstTouchPointLatLon();
                    cacheSecondTouchPoint = view.getSecondTouchPointLatLon();
                    setDistanceText(cacheFirstTouchPoint.getLatitude(), cacheFirstTouchPoint.getLongitude(), cacheSecondTouchPoint.getLatitude(), cacheSecondTouchPoint.getLongitude());
                    fingerAndLocDistWasShown = false;
                }
            } else {
                LatLon centerLoc = map.getMapLocation();
                if (currentLoc != null && centerLoc != null) {
                    if (map.getMapViewTrackingUtilities().isMapLinkedToLocation()) {
                        setDistanceText(0);
                    } else {
                        setDistanceText(currentLoc.getLatitude(), currentLoc.getLongitude(), centerLoc.getLatitude(), centerLoc.getLongitude());
                    }
                } else {
                    setText(title, null);
                }
            }
            return true;
        }

        private void setDistanceText(float dist) {
            calculateAndSetText(dist);
        }

        private void setDistanceText(double firstLat, double firstLon, double secondLat, double secondLon) {
            float dist = (float) MapUtils.getDistance(firstLat, firstLon, secondLat, secondLon);
            calculateAndSetText(dist);
        }

        private void calculateAndSetText(float dist) {
            String distance = OsmAndFormatter.getFormattedDistance(dist, map.getMyApplication());
            int ls = distance.lastIndexOf(' ');
            setText(distance.substring(0, ls), distance.substring(ls + 1));
        }
    };
    rulerControl.setText(title, null);
    setRulerControlIcon(rulerControl, map.getMyApplication().getSettings().RULER_MODE.get());
    rulerControl.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            final RulerMode mode = map.getMyApplication().getSettings().RULER_MODE.get();
            RulerMode newMode = RulerMode.FIRST;
            if (mode == RulerMode.FIRST) {
                newMode = RulerMode.SECOND;
            } else if (mode == RulerMode.SECOND) {
                newMode = RulerMode.EMPTY;
            }
            setRulerControlIcon(rulerControl, newMode);
            map.getMyApplication().getSettings().RULER_MODE.set(newMode);
            map.refreshMap();
        }
    });
    return rulerControl;
}
Also used : RulerMode(net.osmand.plus.OsmandSettings.RulerMode) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings) LatLon(net.osmand.data.LatLon) RulerControlLayer(net.osmand.plus.views.RulerControlLayer) OnClickListener(android.view.View.OnClickListener) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) Location(net.osmand.Location)

Example 88 with Location

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

the class MapInfoWidgetsFactory method createAltitudeControl.

public TextInfoWidget createAltitudeControl(final MapActivity map) {
    final TextInfoWidget altitudeControl = new TextInfoWidget(map) {

        private int cachedAlt = 0;

        @Override
        public boolean updateInfo(DrawSettings d) {
            // draw speed
            Location loc = map.getMyApplication().getLocationProvider().getLastKnownLocation();
            if (loc != null && loc.hasAltitude()) {
                double compAlt = loc.getAltitude();
                if (cachedAlt != (int) compAlt) {
                    cachedAlt = (int) compAlt;
                    String ds = OsmAndFormatter.getFormattedAlt(cachedAlt, map.getMyApplication());
                    int ls = ds.lastIndexOf(' ');
                    if (ls == -1) {
                        setText(ds, null);
                    } else {
                        setText(ds.substring(0, ls), ds.substring(ls + 1));
                    }
                    return true;
                }
            } else if (cachedAlt != 0) {
                cachedAlt = 0;
                setText(null, null);
                return true;
            }
            return false;
        }
    };
    altitudeControl.setText(null, null);
    altitudeControl.setIcons(R.drawable.widget_altitude_day, R.drawable.widget_altitude_night);
    return altitudeControl;
}
Also used : DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings) Location(net.osmand.Location)

Example 89 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)

Example 90 with Location

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

the class CurrentPositionHelper method getLastKnownRouteSegment.

public RouteDataObject getLastKnownRouteSegment(Location loc) {
    Location last = lastAskedLocation;
    RouteDataObject r = lastFound;
    if (loc == null || loc.getAccuracy() > 50) {
        return null;
    }
    if (last != null && last.distanceTo(loc) < 10) {
        return r;
    }
    if (r == null) {
        scheduleRouteSegmentFind(loc, true, null, null);
        return null;
    }
    double d = getOrthogonalDistance(r, loc);
    if (d > 15) {
        scheduleRouteSegmentFind(loc, true, null, null);
    }
    if (d < 70) {
        return r;
    }
    return null;
}
Also used : RouteDataObject(net.osmand.binary.RouteDataObject) 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