Documentation Index Fetch the complete documentation index at: https://mintlify.com/kingstinct/react-native-healthkit/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Workout routes allow you to attach GPS location data to workouts. The WorkoutProxy object provides methods to retrieve existing routes and save new ones.
getWorkoutRoutes
Retrieve all GPS routes associated with a workout.
Signature
workoutProxy . getWorkoutRoutes (): Promise < readonly WorkoutRoute [] >
Returns
Array of workout routes, each containing location data Show WorkoutRoute properties
Array of location points along the route Show WorkoutRouteLocation properties
Timestamp of this location
Speed in meters per second
Direction of travel in degrees (0-360)
Horizontal accuracy in meters
Vertical accuracy in meters
Speed accuracy in meters per second
Distance traveled since previous point in meters (optional)
HKMetadataKeySyncIdentifier
Sync identifier from metadata (optional)
Sync version from metadata (optional)
Example
import { queryWorkoutSamples , WorkoutActivityType } from '@kingstinct/react-native-healthkit'
// Get a recent running workout
const workouts = await queryWorkoutSamples ({
filter: {
workoutActivityType: WorkoutActivityType . running ,
},
limit: 1 ,
ascending: false ,
})
if ( workouts . length > 0 ) {
const workout = workouts [ 0 ]
const routes = await workout . getWorkoutRoutes ()
console . log ( `Found ${ routes . length } routes for workout` )
for ( const route of routes ) {
console . log ( `Route with ${ route . locations . length } locations` )
// Access location data
for ( const location of route . locations ) {
console . log ( `Location: ${ location . latitude } , ${ location . longitude } ` , {
altitude: location . altitude ,
speed: location . speed ,
accuracy: location . horizontalAccuracy ,
timestamp: location . date ,
})
}
}
}
saveWorkoutRoute
Save a GPS route for a workout. This associates location data with the workout sample.
Signature
workoutProxy . saveWorkoutRoute (
locations : readonly LocationForSaving []
): Promise < boolean >
Parameters
locations
LocationForSaving[]
required
Array of location points to save. Each location should have a timestamp within the workout’s time range. Show LocationForSaving properties
Timestamp of this location point
Speed in meters per second
Direction of travel in degrees (0-360)
Horizontal accuracy in meters
Vertical accuracy in meters
Returns
Returns true if the route was successfully saved
Example
import { saveWorkoutSample , WorkoutActivityType } from '@kingstinct/react-native-healthkit'
import * as Location from 'expo-location'
// Start tracking location during workout
const locations : LocationForSaving [] = []
const startDate = new Date ()
// Record locations during workout (example using expo-location)
const locationSubscription = await Location . watchPositionAsync (
{
accuracy: Location . Accuracy . BestForNavigation ,
distanceInterval: 10 , // meters
},
( location ) => {
locations . push ({
latitude: location . coords . latitude ,
longitude: location . coords . longitude ,
altitude: location . coords . altitude ?? 0 ,
date: new Date ( location . timestamp ),
speed: location . coords . speed ?? 0 ,
course: location . coords . heading ?? 0 ,
horizontalAccuracy: location . coords . accuracy ?? 0 ,
verticalAccuracy: location . coords . altitudeAccuracy ?? 0 ,
})
}
)
// ... workout happens ...
// End workout
const endDate = new Date ()
locationSubscription . remove ()
// Save workout
const workout = await saveWorkoutSample (
WorkoutActivityType . running ,
[], // quantity samples
startDate ,
endDate ,
{
distance: 5000 ,
energyBurned: 350 ,
}
)
// Save the route
const routeSaved = await workout . saveWorkoutRoute ( locations )
if ( routeSaved ) {
console . log ( `Route saved with ${ locations . length } locations` )
} else {
console . error ( 'Failed to save route' )
}
You must request write authorization for HKWorkoutRouteTypeIdentifier before saving workout routes.
Location points should be ordered chronologically and fall within the workout’s start and end dates for accurate route representation.