Add elevation gain information to HKWorkout - ios

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?

These are the only metadata keys related to elevation that can be added to a workout in HealthKit:
HKMetadataKeyElevationAscended
HKMetadataKeyElevationDescended
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.

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 CLLocations 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?

Related

iOS - is it possible to get a history of user locale/timezones programmatically for HealthKit apps?

I have an app that is reading data from HealthKit and is calculating sleep statistics for the user going 3 years back. One data point I can offer to the user is the sunrise/sunset times for the current location.
However, if the user has travelled over the last 3 years, then sunrise/sunset calculation needs to be performed on that coordinate, not the present location.
How can I obtain history of time zone or coordinates for the user? (rough 100-500km accuracy) Is this information recored anywhere in HealthKit?
You can check if the samples have metadata value for the key HKMetadataKeyTimeZone

Apple Fitness -> Map not always shown

In my app the user can record activities and I also store them in Apple-Health.
For each HKWorkout that I create I also save a HKWorkoutRoute of the path the user took.
The workouts are properly visible in the Fitness app with data like duration, distance, ... Fine. But the route (the MapView with the track) is not always displayed in the Fitness App. Sometime it is, sometimes it's not. If I query the same HKWorkout object for its' route in my code, it finds it, but it will just not display it in the Fitness App.
Now I got a user-complaint why that is now properly shown. And I don't really know where to start digging. So any hint is greatly appreciated!
Also... is there a way to check the data in the Health app? I couldn't find a way to do so.

xCode show app users on inapp map services

I've recently started to learn how to develop with Xcode and I have a question about the map and gps services.
Does anyone know what kind of resources I would have to use if I wanted to have a map in my app that shows the location of other people who use the app?
I have a general idea that each person would need an account for my app,
But would I have to put everyone's gps coordinates onto a server (SQLite?) and then constantly make the app fetch this information?
I am aiming for a similar concept that the app Called "Uber" uses where you can see taxi drivers around you and they are moving.
Yeah, you will probably need to store each user's GPS coordinates somewhere in a database. Then you can draw annotations on Apple's map view or on a map view that Google provides in their iOS helper once you fetch information from the database. I would not constantly update the user's map though. You should update it every 5 minutes, or when the user asks for it to be refreshed either through a button or some other form. Also if you plan to find the nearest user to them from the database I recommend using the Haversine Forumula (http://rosettacode.org/wiki/Haversine_formula).

GPS location tracking of others in Corona SDK

I am building an iOS app in Corona SDK and am trying to implement a map feature where the user can see where they are compared to where others with the app open are. What would be the best way to go at this?
I already wrote the code for finding the current location of the owner of the device, but how do I retrieve data from other users?
Any advice is greatly appreciated!
This is very broad question, but basically you need a server (on the web) where each user's location gets stored while the app is open, and the app can request the location of other users specifically, at some time interval. Presumably you would need to have some form of rights management since every user would typically be interested in seeing only a small number of other users, and every user would want to have control over who can see their location.
One thing to remind users of is that the reported position is that of the device, not that of the user, and that it is the last reported position, not necessarily current (not all devices are on cellular network or wifi at every moment), so you'd also want a time-of-last-update to be shown with every location marker.

What google map and Apple map did to show MORE accurate location?

In my app, I am using CLLocationManager to get user's current location.
The problem is, most of the time, user would be indoor, or not very far from the building entrance when they launch my app for the very first time. As a result the location I get is not very accurate(more than 1km off).
Yet, at the same time, if I open either Google Map or Apple Map, they are able to display location with little discrepency(a few hundred meters). How they manage to do that ?

Resources