private function writeTrackPoints(\XMLWriter $xmlWriter, array $trackPoints)
    {
        $previousTrackPoint = null;
        foreach ($trackPoints as $trackPoint) {
            $xmlWriter->startElement('Trackpoint');

            // Time of position
            $dateTime = clone $trackPoint->dateTime();
            $dateTime->setTimezone(new \DateTimeZone('UTC'));
            $xmlWriter->writeElement('Time', $this->formatDateTime($dateTime));

            // Position.
            $xmlWriter->startElement('Position');
            $xmlWriter->writeElement('LatitudeDegrees', (string)$trackPoint->latitude());
            $xmlWriter->writeElement('LongitudeDegrees', (string)$trackPoint->longitude());
            $xmlWriter->endElement();

            // Elevation.
            $xmlWriter->writeElement('AltitudeMeters', (string)$trackPoint->elevation());

            // Distance.
            if ($previousTrackPoint !== null) {
                $xmlWriter->writeElement('DistanceMeters', (string)$trackPoint->distanceFromPoint($previousTrackPoint));
            } else {
                $xmlWriter->writeElement('DistanceMeters', '0');
            }

            // Extensions.
            $this->writeExtensions($xmlWriter, $trackPoint->extensions());

            $xmlWriter->endElement();

            $previousTrackPoint = $trackPoint;
        }
    }