Strava api to export GPX file of activity
Closest I could get is using the streams API as described in other posts.
StreamSet streamSet = streamsApi.getActivityStreams(activityId as long, ['latlng', 'altitude', 'time'], true)
def altitudes = streamSet.getAltitude().getData()
def latLong = streamSet.getLatlng().getData()
def times = streamSet.getTime().getData()
ArrayList<StreamData> data = []
for (int i = 0; i < times.size(); i++) {
StreamData streamData = new StreamData()
streamData.id = activityId as long
streamData.time = times[i]
streamData.startTime = startTime
streamData.altitude = altitudes[i]
streamData.latitude = latLong[i][0]
streamData.longitude = latLong[i][1]
data << streamData
}
and then building my own GPX file from it:
def stringWriter = new StringWriter()
def gpxBuilder = new MarkupBuilder(stringWriter)
gpxBuilder.mkp.xmlDeclaration(version: "1.0", encoding: "utf-8")
gpxBuilder.gpx() {
metadata() {
time(startTime)
}
trk() {
name(NEW_ACTIVITY_NAME)
type(convertedType)
trkseg() {
for (def item : streamData) {
trkpt(lat: item.latitude, lon: item.longitude) {
ele(item.altitude)
time(UtcTimeString)
}
}
}
}
}
stringWriter.toString()
Uploading this to Strava works well.