PHP code example of sportlog / fit
1. Go to this page and download the library: Download sportlog/fit library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sportlog / fit example snippets
portlog\FIT\Decoder;
use Sportlog\FIT\Profile\Messages\SessionMessage;
use Sportlog\FIT\Profile\Types\MesgNum;
$decoder = new Decoder();
// Decoding the FIT file returns a set of messages
$messageList = $decoder->read('yourfile.fit');
echo "File type: " . $messageList->getFileType();
// You can iterate over the message list, or like in this example,
// iterate over the messages grouped by their message numbers.
foreach ($messageList->getMessageNumbers() as $messageNumber) {
$messages = $messageList->getMessages($messageNumber);
echo sprintf('%s: %s', $messageNumber, count($messages));
}
// You can also grab specific messages
$sessionMessages = $messageList->getMessages(MesgNum::SESSION);
// There should be one session message (add check!)
/** @var SessionMessage $sessionMessage */
$sessionMessage = $sessionMessages[0];
// get any native fields from the message; use intellisense
echo "Total time (m): " . $lastRecordMessage->getTotalElapsedTime();
echo "Total distance (m): " . $lastRecordMessage->getTotalDistance();
echo "Total ascent (m): " . $lastRecordMessage->getTotalAscent();