forked from upstream-mirrors/OpenTracks
Support importing gpx and kml without altitude value.
This commit is contained in:
@@ -96,8 +96,6 @@ abstract class AbstractImporter extends DefaultHandler {
|
||||
int numBufferedLocations = 0;
|
||||
}
|
||||
|
||||
protected static final String DEFAULT_ALTITUDE = "0";
|
||||
|
||||
// The maximum number of buffered locations for bulk-insertion
|
||||
private static final int MAX_BUFFERED_LOCATIONS = 512;
|
||||
|
||||
@@ -465,24 +463,29 @@ abstract class AbstractImporter extends DefaultHandler {
|
||||
* Creates a location.
|
||||
*/
|
||||
private Location createLocation() throws SAXException {
|
||||
if (latitude == null || longitude == null || altitude == null) {
|
||||
if (latitude == null || longitude == null) {
|
||||
return null;
|
||||
}
|
||||
double longitudeValue;
|
||||
double latitudeValue;
|
||||
double altitudeValue;
|
||||
|
||||
double longitudeValue;
|
||||
try {
|
||||
longitudeValue = Double.parseDouble(longitude);
|
||||
latitudeValue = Double.parseDouble(latitude);
|
||||
altitudeValue = Double.parseDouble(altitude);
|
||||
longitudeValue = Double.parseDouble(longitude);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new SAXException(createErrorMessage(String.format(
|
||||
"Unable to parse longitude latitude altitude: %s %s %s", longitude, latitude, altitude)),
|
||||
e);
|
||||
throw new SAXException(createErrorMessage(
|
||||
String.format("Unable to parse latitude longitude: %s %s", latitude, longitude)), e);
|
||||
}
|
||||
Double altitudeValue = null;
|
||||
if (altitude != null) {
|
||||
try {
|
||||
altitudeValue = Double.parseDouble(altitude);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new SAXException(
|
||||
createErrorMessage(String.format("Unable to parse altitude: %s", altitude)), e);
|
||||
}
|
||||
}
|
||||
|
||||
long timeValue;
|
||||
|
||||
if (time == null) {
|
||||
timeValue = trackData.importTime;
|
||||
} else {
|
||||
@@ -505,11 +508,15 @@ abstract class AbstractImporter extends DefaultHandler {
|
||||
* @param timeValue the time value
|
||||
*/
|
||||
private Location createLocation(
|
||||
double latitudeValue, double longitudeValue, double altitudeValue, long timeValue) {
|
||||
double latitudeValue, double longitudeValue, Double altitudeValue, long timeValue) {
|
||||
Location location = new Location(LocationManager.GPS_PROVIDER);
|
||||
location.setLatitude(latitudeValue);
|
||||
location.setLongitude(longitudeValue);
|
||||
location.setAltitude(altitudeValue);
|
||||
if (altitudeValue != null) {
|
||||
location.setAltitude(altitudeValue);
|
||||
} else {
|
||||
location.removeAltitude();
|
||||
}
|
||||
location.setTime(timeValue);
|
||||
location.removeAccuracy();
|
||||
location.removeBearing();
|
||||
|
||||
@@ -47,7 +47,7 @@ public class GpxImporter extends AbstractImporter {
|
||||
|
||||
private static final String ATTRIBUTE_LAT = "lat";
|
||||
private static final String ATTRIBUTE_LON = "lon";
|
||||
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@@ -133,7 +133,7 @@ public class GpxImporter extends AbstractImporter {
|
||||
private void onTrackPointStart(Attributes attributes) {
|
||||
latitude = attributes.getValue(ATTRIBUTE_LAT);
|
||||
longitude = attributes.getValue(ATTRIBUTE_LON);
|
||||
altitude = DEFAULT_ALTITUDE;
|
||||
altitude = null;
|
||||
time = null;
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ public class GpxImporter extends AbstractImporter {
|
||||
category = null;
|
||||
latitude = attributes.getValue(ATTRIBUTE_LAT);
|
||||
longitude = attributes.getValue(ATTRIBUTE_LON);
|
||||
altitude = DEFAULT_ALTITUDE;
|
||||
altitude = null;
|
||||
time = null;
|
||||
waypointType = null;
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ public class KmlImporter extends AbstractImporter {
|
||||
category = null;
|
||||
latitude = null;
|
||||
longitude = null;
|
||||
altitude = DEFAULT_ALTITUDE;
|
||||
altitude = null;
|
||||
time = null;
|
||||
waypointType = null;
|
||||
}
|
||||
@@ -181,9 +181,7 @@ public class KmlImporter extends AbstractImporter {
|
||||
}
|
||||
longitude = parts[0];
|
||||
latitude = parts[1];
|
||||
if (parts.length == 3) {
|
||||
altitude = parts[2];
|
||||
}
|
||||
altitude = parts.length == 3 ? parts[2] : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,12 +238,13 @@ public class KmlImporter extends AbstractImporter {
|
||||
return;
|
||||
}
|
||||
String parts[] = content.trim().split(" ");
|
||||
if (parts.length != 3) {
|
||||
if (parts.length != 2 && parts.length != 3) {
|
||||
return;
|
||||
}
|
||||
longitude = parts[0];
|
||||
latitude = parts[1];
|
||||
altitude = parts[2];
|
||||
altitude = parts.length == 3 ? parts[2] : null;
|
||||
|
||||
Location location = getTrackPoint();
|
||||
if (location == null) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user