我正在尝试制作一个非常基本的Processing 3草图,在那里我绘制了我的手表在我的自行车骑行中跟踪的纬度和经度点。
我能够从位置源解析XML数据,并且我已经使用XML文件设置了一个数据文件夹。我似乎没有解析数据的问题。
但是,我正在尝试将纬度/长度GPS数据映射到屏幕尺寸,我认为它没有正常工作。
我的工作方式是lat / long以正确的比例显示。 虽然现在,它旋转不正确。
我附上了一张图片。左图是它的外观,右图是它的外观。看起来点/ GPS需要逆时针旋转90度。
也许这是我的地图()?
// 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);
无论如何,这是我的处理代码。任何帮助都表示赞赏,因为我已经陷入困境,我认为这是最后一点需要解决的问题。
谢谢! 亚伦
// 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);
}
}