use of com.peterlaurence.trekadvisor.util.gpx.model.TrackPoint in project TrekAdvisor by peterLaurence.
the class GPXTest method writeTest.
/**
* Tests the gpx writer against the gpx parser : parse an existing gpx file, the use the gpx
* writer to write a gpx file somewhere in a temp folder, then use the gpx parser again to parse
* the resulting file. <br>
* The resulting file should have identical values (at least for tags that the writer supports).
*/
@Test
public void writeTest() {
try {
/* First read an existing gpx file */
Gpx gpxInput = null;
try {
gpxInput = GPXParser.parse(new FileInputStream(referenceGpxFile));
} catch (Exception e) {
e.printStackTrace();
fail();
}
/* Write it in a temporary folder */
File testFile = mTestFolder.newFile();
FileOutputStream fos = new FileOutputStream(testFile);
GPXWriter.write(gpxInput, fos);
/* Now read it back */
Gpx gpx = GPXParser.parse(new FileInputStream(testFile));
List<Track> trackList = gpx.getTracks();
assertEquals(1, trackList.size());
Track track = trackList.get(0);
List<TrackSegment> trackSegmentList = track.getTrackSegments();
assertEquals("Example track", track.getName());
assertEquals(1, trackSegmentList.size());
TrackSegment trackSegment = trackSegmentList.get(0);
List<TrackPoint> trackPointList = trackSegment.getTrackPoints();
assertEquals(7, trackPointList.size());
TrackPoint firstTrackPoint = trackPointList.get(0);
Double lat = firstTrackPoint.getLatitude();
Double lon = firstTrackPoint.getLongitude();
Double elevation = firstTrackPoint.getElevation();
assertEquals(46.57608333, lat);
assertEquals(8.89241667, lon);
assertEquals(2376.0, elevation);
assertEquals(firstTrackPoint.getTime(), new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH).parse("2007-10-14T10:09:57Z"));
} catch (IOException | ParserConfigurationException | TransformerException | ParseException | XmlPullParserException e) {
e.printStackTrace();
fail();
}
}
use of com.peterlaurence.trekadvisor.util.gpx.model.TrackPoint in project TrekAdvisor by peterLaurence.
the class GPXTest method simpleFileTest.
@Test
public void simpleFileTest() {
if (mGpxFilesDirectory != null) {
if (referenceGpxFile.exists()) {
try {
Gpx gpx = GPXParser.parse(new FileInputStream(referenceGpxFile));
List<Track> trackList = gpx.getTracks();
assertEquals(1, trackList.size());
Track track = trackList.get(0);
List<TrackSegment> trackSegmentList = track.getTrackSegments();
assertEquals("Example track", track.getName());
assertEquals(1, trackSegmentList.size());
TrackSegment trackSegment = trackSegmentList.get(0);
List<TrackPoint> trackPointList = trackSegment.getTrackPoints();
assertEquals(7, trackPointList.size());
TrackPoint firstTrackPoint = trackPointList.get(0);
Double lat = firstTrackPoint.getLatitude();
Double lon = firstTrackPoint.getLongitude();
Double elevation = firstTrackPoint.getElevation();
assertEquals(46.57608333, lat);
assertEquals(8.89241667, lon);
assertEquals(2376.0, elevation);
assertEquals(firstTrackPoint.getTime(), new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH).parse("2007-10-14T10:09:57Z"));
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
}
}
use of com.peterlaurence.trekadvisor.util.gpx.model.TrackPoint in project TrekAdvisor by peterLaurence.
the class LocationService method onCreate.
@Override
public void onCreate() {
EventBus.getDefault().register(this);
/* Start up the thread running the service. Note that we create a separate thread because
* the service normally runs in the process's main thread, which we don't want to block.
* We also make it background priority so CPU-intensive work will not disrupt our UI.
*/
HandlerThread thread = new HandlerThread("LocationServiceThread", Thread.MIN_PRIORITY);
thread.start();
/* Get the HandlerThread's Looper and use it for our Handler */
mServiceLooper = thread.getLooper();
mServiceHandler = new Handler(mServiceLooper);
mServiceHandler.handleMessage(new Message());
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this.getApplicationContext());
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(1000);
mLocationRequest.setFastestInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
/* Create the Gpx instance */
mTrackPoints = new ArrayList<>();
mLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
for (Location location : locationResult.getLocations()) {
mServiceHandler.post(() -> {
TrackPoint.Builder pointBuilder = new TrackPoint.Builder();
pointBuilder.setLatitude(location.getLatitude());
pointBuilder.setLongitude(location.getLongitude());
pointBuilder.setElevation(location.getAltitude());
TrackPoint trackPoint = pointBuilder.build();
mTrackPoints.add(trackPoint);
});
}
}
};
startLocationUpdates();
}
use of com.peterlaurence.trekadvisor.util.gpx.model.TrackPoint in project TrekAdvisor by peterLaurence.
the class GPXWriter method addTrackSegmentToNode.
private static void addTrackSegmentToNode(TrackSegment ts, Node n, Document doc) {
Node tsNode = doc.createElement(TAG_SEGMENT);
for (TrackPoint trkpt : ts.getTrackPoints()) {
addWaypointToNode(TAG_POINT, trkpt, tsNode, doc);
}
n.appendChild(tsNode);
}
Aggregations