Skip to content

Error on Upload GPX File #117

@Numanshakir

Description

@Numanshakir

/// Generates a Strava-compatible GPX file from provided data
Future generateStravaCompatibleGpxFile({
required String activityName,
required String creator,
required List points,
String activityType = 'running', // match tag
DateTime? metadataTime,
}) async {
StringBuffer buffer = StringBuffer();

// GPX XML Header with required namespaces and schema
buffer.writeln('<?xml version="1.0" encoding="UTF-8"?>');
buffer.writeln(
  '<gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
  'xsi:schemaLocation="http://www.topografix.com/GPX/1/1 '
  'http://www.topografix.com/GPX/1/1/gpx.xsd" '
  'creator="$creator" version="1.1" xmlns="http://www.topografix.com/GPX/1/1">',
);

// Metadata
final metaTime = metadataTime ?? (points.isNotEmpty ? points.first.time : DateTime.now());
final metaTimeStr = metaTime.toUtc().toIso8601String().replaceFirst(RegExp(r'\.\d+'), '') + 'Z';
buffer.writeln('  <metadata>');
buffer.writeln('    <time>$metaTimeStr</time>');
buffer.writeln('  </metadata>');

// Track
buffer.writeln('  <trk>');
buffer.writeln('    <name>$activityName</name>'); // Use activityName here
buffer.writeln('    <type>$activityType</type>');
buffer.writeln('    <trkseg>');

for (final point in points) {
  // CRITICAL FIX: Include time and elevation (if available) for each track point
  final timeStr = point.time.toUtc().toIso8601String().replaceFirst(RegExp(r'\.\d+'), '') + 'Z';
  buffer.writeln('      <trkpt lat="${point.latitude}" lon="${point.longitude}">');
  if (point.elevation != null) {
    buffer.writeln('        <ele>${point.elevation}</ele>');
  }
  buffer.writeln('        <time>$timeStr</time>');
  buffer.writeln('      </trkpt>');
}

buffer.writeln('    </trkseg>');
buffer.writeln('  </trk>');
buffer.writeln('</gpx>');

// Write to temporary file
final dir = await getTemporaryDirectory();
final file = File('${dir.path}/runflo_${DateTime.now().millisecondsSinceEpoch}.gpx');
await file.writeAsString(buffer.toString());
log("Generated GPX Content:\n${buffer.toString()}"); // Keep this for debugging
return file;

}

this is my model
class GpxPoint {
final double latitude;
final double longitude;
final double? elevation; // optional
final DateTime time;

GpxPoint({
required this.latitude,
required this.longitude,
required this.time,
this.elevation,
});
}

Every time i upload api response is 200 but error message is
"Error Processing Data"
"There was an error processing your activity."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions