diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteImporter.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteImporter.java index 2635328d4c..c0f09e970d 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteImporter.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteImporter.java @@ -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 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); } diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java index 56bc5beac4..70e7d5f9f2 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteSegmentResult.java @@ -245,8 +245,12 @@ public class RouteSegmentResult implements StringExternalizable prevLocation = location; object.pointsX[i] = MapUtils.get31TileNumberX(location.getLongitude()); object.pointsY[i] = MapUtils.get31TileNumberY(location.getLatitude()); - object.heightDistanceArray[i * 2] = (float) dist; - object.heightDistanceArray[i * 2 + 1] = (float) location.getAltitude(); + 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 {