'Adding location data to Google Fit

I'm writing an application in Python to add data to Google Fit. I am successful in creating data sources and adding datasets with points for heart rate, cadence, speed, steps, etc. as well as sessions for those datasets.

I am now trying to add location data so that activities in Google Fit show maps of the activity but not having any luck with that. Something that is unclear to me is that while all of the above items are a single data point, location is 4 data points according to https://developers.google.com/fit/datatypes/location#location_sample.

Do these 4 different items in the data point need to be named in any way, or do I just add them as 4 fpVals one after another in the same order as described on the above reference? I.e. in building my array of points for the dataset's patch operation do I just add them to the value array as such:

                gfit_loc.append(dict(
                  dataTypeName='com.google.location.sample',
                  endTimeNanos=p.time.timestamp() * 1e9,
                  startTimeNanos=p.time.timestamp() * 1e9,
                  value=[dict(fpVal=p.latitude),
                         dict(fpVal=p.longitude),
                         dict(fpVal=10),
                         dict(fpVal=p.elevation)]
                ))

where the dataset is added with:

        data = service.users().dataSources().datasets().patch(
            userId='me',
            dataSourceId='raw:com.google.location.sample:718486793782',
            datasetId='%s-%s' % (min_log_ns, max_log_ns),
            body=dict(
              dataSourceId='raw:com.google.location.sample:718486793782',
              maxEndTimeNs=max_log_ns,
              minStartTimeNs=min_log_ns,
              point=gfit_loc
            )
        ).execute()


Solution 1:[1]

So it turns out that I was doing everything correctly with a small exception. I was setting the activity type to 95, which is defined as Walking (treadmill) for all activities in my prototype. I had not gotten to allowing the user to specify the activity type and given that 95 is an indoor treadmill activity, Google Fit was simply not showing any location data for the activity in the form of a map.

Once I started using non-treadmill activity types, maps started showing up in my Google Fit activities.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Brian