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

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

Related

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.

Add elevation gain information to HKWorkout

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?

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 ?

Retrieving data of Nearby devices containing same application

I'm developing a chat application, and a requirement is to get the device details for users within some distance (i.e., devices within 100 miles who are using same application). I want to get the details and they should be shown in a UITableView.
There are far too many pieces involved in this for a single answer to include all the code, however I can give you a high-level overview:
You'll need to send the device's current location (found with CLLocationManager) and an identifier to a remote server on applicationDidBecomeActive: and whenever you determine that the user has moved a significant distance.
Your remote server stores these coordinates, the identifier, and a timestamp into a database table and periodically prunes old entries.
When you load the "Nearby Users" screen your devices makes a request with its own location to the server, which returns the list of users within 100 miles. The Haversine formula is the proper way to calculate distances between GPS coordinates. Once you have the results, you can show them in a UITableView.
When the user selects a nearby user, you can use the identifier it sent in step 1 to start brokering a connection between them. This part is highly dependent on your specific chat system.

Resources