Hi there,
I’m trying to make a very basic Processing sketch, where I map out the latitude and longitude points that my watch tracks on my bike rides.
I’m able to parse the XML data from the location source, and I’ve set up a data folder with the XML file. I don’t seem to have a problem with parsing the data.
However, I am trying to Map the lat/long GPS data to the screen dimensions, and I don’t think it’s working out right.
I’ve looked around at many sources, and there never seems to be a good simple example for how to do this. I think the range I’m dealing with deals with small lat/long changes, e.g.:
float mainx = map(pointLat, 37.751, 37.792, 0, width);
float mainy = map(pointLong, -122.39, -122.494, 0, height);
The examples I’ve seen online all have much larger ranges so maybe that’s an issue? I’m not sure.
Anyways, here’s my Processing code and an image of the output. Any help is appreciated, as I’ve gotten stuck and I think this is the last bit to fix.
Thanks!
Aaron
// Example XML
//<Workout workoutActivityType="HKWorkoutActivityTypeCycling" duration="44.19382538398107" durationUnit="min" totalDistance="7.644061515836529" totalDistanceUnit="mi" totalEnergyBurned="300.3060000000002" totalEnergyBurnedUnit="kcal" sourceName="Aaron’s Apple Watch" sourceVersion="4.3" creationDate="2018-05-01 08:35:07 -0700" startDate="2018-05-01 07:50:51 -0700" endDate="2018-05-01 08:35:03 -0700">
//<MetadataEntry key="HKTimeZone" value="America/Los_Angeles"/>
//<MetadataEntry key="HKWeatherTemperature" value="49 degF"/>
//<MetadataEntry key="HKWeatherHumidity" value="82 %"/>
//<WorkoutRoute sourceName="Watch" sourceVersion="11.3" creationDate="2018-05-01 08:58:53 -0700" startDate="2018-05-01 07:51:11 -0700" endDate="2018-05-01 08:34:52 -0700">
// <MetadataEntry key="HKMetadataKeySyncVersion" value="2"/>
// <MetadataEntry key="HKMetadataKeySyncIdentifier" value="F2BEA6D4-4E7E-4867-AAF4-05586B2F753D"/>
// <Location date="2018-05-01 07:51:11 -0700" latitude="37.7514" longitude="-122.493" altitude="74.0396" horizontalAccuracy="2.43753" verticalAccuracy="1.71176" course="28.125" speed="1.56585"/>
gpsPoint[] GPSPOINT;
XML xml;
void setup() {
size(721, 361); //1024, 768
background(255);
smooth();
xml = loadXML("data/bikeRides.xml");
XML[] workoutRoutes = xml.getChildren("Workout/WorkoutRoute");
println("num of workouts " + workoutRoutes.length);
// Parse inside Workouts, workout O
for (int i = 0; i < workoutRoutes.length; i++) {
//int workoutNumber = i+1;
//println("Workout # " + workoutNumber + " //////" );
//workout #1, list Locations, workout 0, Locations in there, go into an Array, get OVERWRITTEN every time? empty Location array everyime
XML[] locations = null;
locations = workoutRoutes[i].getChildren("Location");
println("number of locations in workout: " + locations.length);
//initialize object with number in array, which is number of locations
GPSPOINT = new gpsPoint[locations.length];
//add xvalue and yvalue into object
for (int a = 0; a < locations.length; a++){
//get lat and long
float pointLat = locations[a].getFloat("latitude");
float pointLong = locations[a].getFloat("longitude");
// convert and remap Lat and Long based on range
float mainx = map(pointLat, 37.751, 37.792, 0, width);
float mainy = map(pointLong, -122.39, -122.494, 0, height);
GPSPOINT[a] = new gpsPoint(mainx, mainy);
GPSPOINT[a].display();
}
}
}
void draw() {
}
class gpsPoint {
float prevX;
float prevY;
float newX;
float newY;
gpsPoint(float previousX, float previousY){
prevX = previousX;
prevY = previousY;
}
void display() {
stroke(0, 50);
point(prevX, prevY);
}
}