use of net.osmand.Location in project Osmand by osmandapp.
the class TargetPointsHelper method wrap.
private Location wrap(TargetPoint l) {
if (l == null) {
return null;
}
Location loc = new Location("map");
loc.setLatitude(l.getLatitude());
loc.setLongitude(l.getLongitude());
return loc;
}
use of net.osmand.Location in project Osmand by osmandapp.
the class NavigationInfo method updateTargetDirection.
public synchronized void updateTargetDirection(final LatLon point, float heading) {
if (point != null) {
// $NON-NLS-1$
Location destination = new Location("map");
destination.setLatitude(point.getLatitude());
destination.setLongitude(point.getLongitude());
updateTargetDirection(destination, heading);
}
}
use of net.osmand.Location in project Osmand by osmandapp.
the class NavigationInfo method getDirectionString.
// Get distance and direction string for specified point
public synchronized String getDirectionString(final LatLon apoint, Float heading) {
if ((currentLocation != null) && (apoint != null)) {
Location point = new Location("");
point.setLatitude(apoint.getLatitude());
point.setLongitude(apoint.getLongitude());
RelativeDirection direction = null;
String result = distanceString(point);
// $NON-NLS-1$
result += " ";
if (currentLocation.hasBearing() && !MapViewTrackingUtilities.isSmallSpeedForCompass(currentLocation))
direction = new RelativeDirection(point);
else if (heading != null)
direction = new RelativeDirection(point, heading);
if (direction != null) {
// relative direction
result += direction.getString();
} else {
// absolute direction
// $NON-NLS-1$
result += getString(R.string.towards) + " ";
result += absoluteDirectionString(currentLocation.bearingTo(point));
}
return result;
}
return null;
}
use of net.osmand.Location in project Osmand by osmandapp.
the class RouteCalculationResult method attachAlarmInfo.
private static void attachAlarmInfo(List<AlarmInfo> alarms, RouteSegmentResult res, int intId, int locInd) {
int[] pointTypes = res.getObject().getPointTypes(intId);
if (pointTypes != null) {
RouteRegion reg = res.getObject().region;
for (int r = 0; r < pointTypes.length; r++) {
RouteTypeRule typeRule = reg.quickGetEncodingRule(pointTypes[r]);
int x31 = res.getObject().getPoint31XTile(intId);
int y31 = res.getObject().getPoint31YTile(intId);
Location loc = new Location("");
loc.setLatitude(MapUtils.get31LatitudeY(y31));
loc.setLongitude(MapUtils.get31LongitudeX(x31));
AlarmInfo info = AlarmInfo.createAlarmInfo(typeRule, locInd, loc);
// For STOP first check if it has directional info
if ((info != null) && !((info.getType() == AlarmInfoType.STOP) && !res.getObject().isStopApplicable(res.isForwardDirection(), intId, res.getStartPointIndex(), res.getEndPointIndex()))) {
alarms.add(info);
}
}
}
}
use of net.osmand.Location in project Osmand by osmandapp.
the class RouteCalculationResult method convertVectorResult.
/**
* PREPARATION
*/
private static List<RouteSegmentResult> convertVectorResult(List<RouteDirectionInfo> directions, List<Location> locations, List<RouteSegmentResult> list, List<AlarmInfo> alarms, OsmandApplication ctx) {
float prevDirectionTime = 0;
float prevDirectionDistance = 0;
double lastHeight = HEIGHT_UNDEFINED;
List<RouteSegmentResult> segmentsToPopulate = new ArrayList<RouteSegmentResult>();
AlarmInfo tunnelAlarm = null;
for (int routeInd = 0; routeInd < list.size(); routeInd++) {
RouteSegmentResult s = list.get(routeInd);
float[] vls = s.getObject().calculateHeightArray();
boolean plus = s.getStartPointIndex() < s.getEndPointIndex();
int i = s.getStartPointIndex();
int prevLocationSize = locations.size();
if (s.getObject().tunnel()) {
if (tunnelAlarm == null) {
LatLon latLon = s.getPoint(i);
tunnelAlarm = new AlarmInfo(AlarmInfoType.TUNNEL, prevLocationSize);
tunnelAlarm.setLatLon(latLon.getLatitude(), latLon.getLongitude());
tunnelAlarm.setFloatValue(s.getDistance());
alarms.add(tunnelAlarm);
} else {
tunnelAlarm.setFloatValue(tunnelAlarm.getFloatValue() + s.getDistance());
}
} else {
if (tunnelAlarm != null) {
tunnelAlarm.setLastLocationIndex(locations.size());
}
tunnelAlarm = null;
}
while (true) {
// $NON-NLS-1$
Location n = new Location("");
LatLon point = s.getPoint(i);
n.setLatitude(point.getLatitude());
n.setLongitude(point.getLongitude());
if (i == s.getEndPointIndex() && routeInd != list.size() - 1) {
break;
}
if (vls != null && i * 2 + 1 < vls.length) {
float h = vls[2 * i + 1];
n.setAltitude(h);
if (lastHeight == HEIGHT_UNDEFINED && locations.size() > 0) {
for (Location l : locations) {
if (!l.hasAltitude()) {
l.setAltitude(h);
}
}
}
lastHeight = h;
}
locations.add(n);
attachAlarmInfo(alarms, s, i, locations.size());
segmentsToPopulate.add(s);
if (i == s.getEndPointIndex()) {
break;
}
if (plus) {
i++;
} else {
i--;
}
}
TurnType turn = s.getTurnType();
if (turn != null) {
RouteDirectionInfo info = new RouteDirectionInfo(s.getSegmentSpeed(), turn);
if (routeInd < list.size()) {
int lind = routeInd;
if (turn.isRoundAbout()) {
int roundAboutEnd = prevLocationSize;
// take next name for roundabout (not roundabout name)
while (lind < list.size() - 1 && list.get(lind).getObject().roundabout()) {
roundAboutEnd += Math.abs(list.get(lind).getEndPointIndex() - list.get(lind).getStartPointIndex());
lind++;
}
// Consider roundabout end.
info.routeEndPointOffset = roundAboutEnd;
}
RouteSegmentResult next = list.get(lind);
info.setRef(next.getObject().getRef(ctx.getSettings().MAP_PREFERRED_LOCALE.get(), ctx.getSettings().MAP_TRANSLITERATE_NAMES.get(), next.isForwardDirection()));
info.setStreetName(next.getObject().getName(ctx.getSettings().MAP_PREFERRED_LOCALE.get(), ctx.getSettings().MAP_TRANSLITERATE_NAMES.get()));
info.setDestinationName(next.getObject().getDestinationName(ctx.getSettings().MAP_PREFERRED_LOCALE.get(), ctx.getSettings().MAP_TRANSLITERATE_NAMES.get(), next.isForwardDirection()));
}
String description = toString(turn, ctx, false) + " " + RoutingHelper.formatStreetName(info.getStreetName(), info.getRef(), info.getDestinationName(), ctx.getString(R.string.towards));
description = description.trim();
String[] pointNames = s.getObject().getPointNames(s.getStartPointIndex());
if (pointNames != null) {
for (int t = 0; t < pointNames.length; t++) {
description = description.trim();
description += " " + pointNames[t];
}
}
info.setDescriptionRoute(description);
info.routePointOffset = prevLocationSize;
if (directions.size() > 0 && prevDirectionTime > 0 && prevDirectionDistance > 0) {
RouteDirectionInfo prev = directions.get(directions.size() - 1);
prev.setAverageSpeed(prevDirectionDistance / prevDirectionTime);
prevDirectionDistance = 0;
prevDirectionTime = 0;
}
directions.add(info);
}
prevDirectionDistance += s.getDistance();
prevDirectionTime += s.getSegmentTime();
}
if (directions.size() > 0 && prevDirectionTime > 0 && prevDirectionDistance > 0) {
RouteDirectionInfo prev = directions.get(directions.size() - 1);
prev.setAverageSpeed(prevDirectionDistance / prevDirectionTime);
}
return segmentsToPopulate;
}
Aggregations