Reputation: 3930
Some of my workouts that I tracked with my AppleWatch do have the information about elevation gain in them. Some also show me the max and min altitude of the workout.
I also have an app to track workouts and would like to know how to add this information. I was going through HKQuantityTypeIdentifier
but could not find anything useful there. Then I had a look at HKWorkoutRouteBuilder
which has a metadata dictionary, but also couldn't find any relevant keys there.
Does anybody know how to add information like max/min altitude and the elevation gain to my workouts in HealthKit?
Upvotes: 2
Views: 1293
Reputation: 2168
As @Paolo says you can't add the metadata but you may be able to provide altitude data in the route.
The route is made up of CLLocation
s and that can provide altitude data. I found in my app, that takes a Fitness app route from HealthKit, that I needed to calculate the min/max myself from the altitude data in each CLLocation
in the route.
So I assume that’s how the Fitness app does it. @mxswd informed me on twitter that just providing the altitude isn’t enough, but perhaps there are more properties that need to be set, like verticalAccuracy
?
Upvotes: 0
Reputation: 3955
These are the only metadata keys related to elevation that can be added to a workout in HealthKit:
The numbers for elevation gain, min, and max might be referring to the information shown in the Activity app for workouts that are recorded with the built-in Apple Watch Workouts app (e.g. running, cycling, walking workouts). As far as I know there's no way to add that info from another app using the available Health APIs.
If you compare what the Activity app shows and what the Health shows for that same workout, you can see the Activity app has other info not shown in the HealthKit metadata.
Upvotes: 1