Fix gpx route importing (read ele)

This commit is contained in:
max-klaus 2020-03-19 12:54:39 +03:00
parent 5335d7c3e0
commit 0f2490c747
2 changed files with 12 additions and 2 deletions

View file

@ -22,6 +22,8 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import static net.osmand.binary.RouteDataObject.HEIGHT_UNDEFINED;
public class RouteImporter {
public final static Log log = PlatformUtil.getLog(RouteImporter.class);
@ -48,11 +50,15 @@ public class RouteImporter {
public boolean readExtensions(GPXFile res, XmlPullParser parser) throws Exception {
if (!resources.hasLocations()) {
List<Location> locations = resources.getLocations();
double lastElevation = HEIGHT_UNDEFINED;
if (res.tracks.size() > 0 && res.tracks.get(0).segments.size() > 0 && res.tracks.get(0).segments.get(0).points.size() > 0) {
for (WptPt point : res.tracks.get(0).segments.get(0).points) {
Location loc = new Location("", point.getLatitude(), point.getLongitude());
if (!Double.isNaN(point.ele)) {
loc.setAltitude(point.ele);
lastElevation = point.ele;
} else if (lastElevation != HEIGHT_UNDEFINED) {
loc.setAltitude(lastElevation);
}
locations.add(loc);
}

View file

@ -245,8 +245,12 @@ public class RouteSegmentResult implements StringExternalizable<RouteDataBundle>
prevLocation = location;
object.pointsX[i] = MapUtils.get31TileNumberX(location.getLongitude());
object.pointsY[i] = MapUtils.get31TileNumberY(location.getLatitude());
if (location.hasAltitude() && object.heightDistanceArray.length > 0) {
object.heightDistanceArray[i * 2] = (float) dist;
object.heightDistanceArray[i * 2 + 1] = (float) location.getAltitude();
} else {
object.heightDistanceArray = new float[0];
}
if (plus) {
index++;
} else {