Search in sources :

Example 46 with Location

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

the class PlanRouteFragment method updateLocation.

@Override
public void updateLocation(Location loc) {
    MapActivity mapActivity = getMapActivity();
    if (mapActivity != null) {
        final Location location = mapActivity.getMyApplication().getLocationProvider().getLastStaleKnownLocation();
        boolean newLocation = (this.location == null && location != null) || location == null;
        boolean locationChanged = this.location != null && location != null && this.location.getLatitude() != location.getLatitude() && this.location.getLongitude() != location.getLongitude();
        boolean farEnough = locationChanged && MapUtils.getDistance(this.location.getLatitude(), this.location.getLongitude(), location.getLatitude(), location.getLongitude()) >= MIN_DISTANCE_FOR_RECALCULATE;
        if (newLocation || farEnough) {
            mapActivity.getMyApplication().runInUIThread(new Runnable() {

                @Override
                public void run() {
                    PlanRouteFragment.this.location = location;
                    adapter.reloadData();
                    try {
                        adapter.notifyDataSetChanged();
                    } catch (Exception e) {
                    // to avoid crash because of:
                    // java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling
                    }
                }
            });
        }
    }
}
Also used : MapActivity(net.osmand.plus.activities.MapActivity) Location(net.osmand.Location)

Example 47 with Location

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

the class FavouritesAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    if (holder instanceof FavouritesViewHolder) {
        OsmandApplication app = (OsmandApplication) ((Activity) context).getApplication();
        IconsCache iconsCache = app.getIconsCache();
        FavouritesViewHolder favouritesViewHolder = (FavouritesViewHolder) holder;
        FavouritePoint favouritePoint = getItem(position);
        favouritesViewHolder.title.setText(favouritePoint.getName());
        if (favouritePoint.getCategory().equals("")) {
            favouritesViewHolder.description.setText(R.string.shared_string_favorites);
        } else {
            favouritesViewHolder.description.setText(favouritePoint.getCategory());
        }
        Location myloc = app.getLocationProvider().getLastKnownLocation();
        favouritesViewHolder.favouriteImage.setImageDrawable(FavoriteImageDrawable.getOrCreate(context, favouritePoint.getColor(), false));
        if (myloc == null) {
            return;
        }
        float dist = (float) MapUtils.getDistance(favouritePoint.getLatitude(), favouritePoint.getLongitude(), myloc.getLatitude(), myloc.getLongitude());
        favouritesViewHolder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, app));
        favouritesViewHolder.arrowImage.setImageDrawable(iconsCache.getIcon(R.drawable.ic_direction_arrow));
        DashLocationFragment.updateLocationView(useCenter, location, heading, favouritesViewHolder.arrowImage, favouritesViewHolder.distance, favouritePoint.getLatitude(), favouritePoint.getLongitude(), screenOrientation, app, context);
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) FavouritePoint(net.osmand.data.FavouritePoint) IconsCache(net.osmand.plus.IconsCache) Location(net.osmand.Location)

Example 48 with Location

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

the class NavigationInfo method updateLocation.

@Override
public synchronized void updateLocation(Location location) {
    currentLocation = location;
    if (autoAnnounce && app.accessibilityEnabled()) {
        final TargetPoint point = app.getTargetPointsHelper().getPointToNavigate();
        if (point != null) {
            if ((currentLocation != null) && currentLocation.hasBearing() && !MapViewTrackingUtilities.isSmallSpeedForCompass(currentLocation)) {
                final long now = SystemClock.uptimeMillis();
                if ((now - lastNotificationTime) >= settings.ACCESSIBILITY_AUTOANNOUNCE_PERIOD.get()) {
                    // $NON-NLS-1$
                    Location destination = new Location("map");
                    destination.setLatitude(point.getLatitude());
                    destination.setLongitude(point.getLongitude());
                    if (lastDirection.update(destination) || !settings.ACCESSIBILITY_SMART_AUTOANNOUNCE.get()) {
                        // $NON-NLS-1$
                        final String notification = distanceString(destination) + " " + lastDirection.getString();
                        lastNotificationTime = now;
                        app.runInUIThread(new Runnable() {

                            @Override
                            public void run() {
                                app.showToastMessage(notification);
                            }
                        });
                    }
                }
            } else {
                lastDirection.clear();
            }
        }
    }
}
Also used : TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) Location(net.osmand.Location)

Example 49 with Location

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

the class OsmAndLocationSimulation method middleLocation.

public static Location middleLocation(Location start, Location end, float meters) {
    double lat1 = toRad(start.getLatitude());
    double lon1 = toRad(start.getLongitude());
    // radius of earth in km
    double R = 6371;
    // in km
    double d = meters / 1000;
    float brng = (float) (toRad(start.bearingTo(end)));
    double lat2 = Math.asin(Math.sin(lat1) * Math.cos(d / R) + Math.cos(lat1) * Math.sin(d / R) * Math.cos(brng));
    double lon2 = lon1 + Math.atan2(Math.sin(brng) * Math.sin(d / R) * Math.cos(lat1), Math.cos(d / R) - Math.sin(lat1) * Math.sin(lat2));
    Location nl = new Location(start);
    nl.setLatitude(toDegree(lat2));
    nl.setLongitude(toDegree(lon2));
    nl.setBearing(brng);
    return nl;
}
Also used : Location(net.osmand.Location)

Example 50 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, false, null, null, null);
        return null;
    }
    double d = getOrthogonalDistance(r, loc);
    if (d > 15) {
        scheduleRouteSegmentFind(loc, true, false, null, 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