I'm trying to make a very basic Processing 3 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 got it working in terms of lat/long showing up in the correct proportions. Although now, it's rotated incorrectly.
I've attached an image. The Left image is how it looks, and the Right image is how it should look. It looks like the the dots/GPS need to be rotated 90deg counterclockwise.
Maybe it's something with my map()?
// convert and remap Lat and Long based on range
// -122.5367,37.6659,-122.3383,37.8174
float mainx = map(pointLat, 37.6659, 37.8174, 0, width);
float mainy = map(pointLong, -122.5367, -122.3383, 0, height);
Anyways, here's my Processing code. 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[] gpsPoints;
PImage backgroundMap;
float mapScreenWidth,mapScreenHeight; // Dimension of map in pixels.
XML xml;
void setup() {
size(400, 386); // 7x7
//background(255);
backgroundMap = loadImage("img/7x7.png");
mapScreenWidth = width;
mapScreenHeight = height;
image(backgroundMap,0,0,mapScreenWidth,mapScreenHeight);
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
gpsPoints = 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
// -122.5367,37.6659,-122.3383,37.8174
float mainx = map(pointLat, 37.6659, 37.8174, 0, width);
float mainy = map(pointLong, -122.5367, -122.3383, 0, height);
gpsPoints[a] = new gpsPoint(mainx, mainy);
gpsPoints[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);
}
}
y
, but you are mapping longitude toy
.