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