Fix gpx route importing (read ele)
This commit is contained in:
parent
5335d7c3e0
commit
0f2490c747
2 changed files with 12 additions and 2 deletions
|
@ -22,6 +22,8 @@ import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static net.osmand.binary.RouteDataObject.HEIGHT_UNDEFINED;
|
||||||
|
|
||||||
public class RouteImporter {
|
public class RouteImporter {
|
||||||
|
|
||||||
public final static Log log = PlatformUtil.getLog(RouteImporter.class);
|
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 {
|
public boolean readExtensions(GPXFile res, XmlPullParser parser) throws Exception {
|
||||||
if (!resources.hasLocations()) {
|
if (!resources.hasLocations()) {
|
||||||
List<Location> locations = resources.getLocations();
|
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) {
|
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) {
|
for (WptPt point : res.tracks.get(0).segments.get(0).points) {
|
||||||
Location loc = new Location("", point.getLatitude(), point.getLongitude());
|
Location loc = new Location("", point.getLatitude(), point.getLongitude());
|
||||||
if (!Double.isNaN(point.ele)) {
|
if (!Double.isNaN(point.ele)) {
|
||||||
loc.setAltitude(point.ele);
|
loc.setAltitude(point.ele);
|
||||||
|
lastElevation = point.ele;
|
||||||
|
} else if (lastElevation != HEIGHT_UNDEFINED) {
|
||||||
|
loc.setAltitude(lastElevation);
|
||||||
}
|
}
|
||||||
locations.add(loc);
|
locations.add(loc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -245,8 +245,12 @@ public class RouteSegmentResult implements StringExternalizable<RouteDataBundle>
|
||||||
prevLocation = location;
|
prevLocation = location;
|
||||||
object.pointsX[i] = MapUtils.get31TileNumberX(location.getLongitude());
|
object.pointsX[i] = MapUtils.get31TileNumberX(location.getLongitude());
|
||||||
object.pointsY[i] = MapUtils.get31TileNumberY(location.getLatitude());
|
object.pointsY[i] = MapUtils.get31TileNumberY(location.getLatitude());
|
||||||
|
if (location.hasAltitude() && object.heightDistanceArray.length > 0) {
|
||||||
object.heightDistanceArray[i * 2] = (float) dist;
|
object.heightDistanceArray[i * 2] = (float) dist;
|
||||||
object.heightDistanceArray[i * 2 + 1] = (float) location.getAltitude();
|
object.heightDistanceArray[i * 2 + 1] = (float) location.getAltitude();
|
||||||
|
} else {
|
||||||
|
object.heightDistanceArray = new float[0];
|
||||||
|
}
|
||||||
if (plus) {
|
if (plus) {
|
||||||
index++;
|
index++;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue