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
}
}
});
}
}
}
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);
}
}
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();
}
}
}
}
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;
}
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;
}
Aggregations