<?phpnamespace App\Utils;use phpGPX\phpGPX;// VOIR DOC SUR phpGPX EN FIN DE CE FICHIERclass Gpx{ private string $filename; private $phpGpxfile; public function __construct($filename) { $this->filename = $filename; $this->phpGpxfile = (new phpGPX)->load($filename); } public function getPhpGpxfile() { return $this->phpGpxfile; } public function getFilename() { return $this->filename; } public function getKm() { // return self::getInfos($filename)["distance"]; en mètre return self::getInfos()["km"] ; } // getInfos($filename) : extrait une sélection d'infos d'une trace GPX // // Pas robuste pour l'instant : seule la première piste est traitée // // PARAMS: chemin d'in fichier gpx // RETURN // un array associatif avec les clés suivantes // - à détailler // public function getInfos() { $gpx = new phpGPX(); $gpxfile = $gpx->load($this->filename); dump($gpxfile); $track1 = $gpxfile->tracks[0]; // dump($track1->stats->toArray()); $infos["name"] = $track1->name; $infos["comment"] = $track1->comment; $infos["description"] = $track1->description; $infos["distance"] = $track1->stats->distance; // car distance est en mètres $infos["km"] = round($track1->stats->distance)/1000; // car distance est en mètres // $infos["stats"] = $track1->stats; $infos["stats"] = $track1->stats->toArray(); return $infos; }}// EXTRAIT DE : https://sibyx.github.io/phpGPX///// phpGPX\Models\GpxFile {#440 ▼// +waypoints: []// +routes: []// +tracks: array:1 [▼// 0 => phpGPX\Models\Track {#444 ▼// +name: "9241313-MN rougeau"// +comment: null// +description: null// +source: null// +links: []// +number: null// +type: null// +extensions: null// +stats: phpGPX\Models\Stats {#628 ▼// +distance: 9196.8627613778// +realDistance: 9208.5165985748// +averageSpeed: 1.3888346060673// +averagePace: 720.02814131456// +minAltitude: 58.0// +maxAltitude: 94.0// +cumulativeElevationGain: 111.0// +cumulativeElevationLoss: 111.0// +startedAt: DateTime @1660117195 {#455 ▼// date: 2022-08-10 07:39:55.0 UTC (+00:00)// }// +finishedAt: DateTime @1660123817 {#631 ▶}// +duration: 6622// }// +segments: array:1 [▶]// }// ]// +metadata: null// +extensions: null// +creator: "Openrunner - https://www.openrunner.com"// }// ...// foreach ($file->tracks as $track) {// Statistics for whole track// $track->stats->toArray();// foreach ($track->segments as $segment) {// // Statistics for segment of track// $segment->stats->toArray();// }// dump($track->stats->toArray());// }// ...//// Exemple de manipulation// // Creating sample Metadata object// $gpx_file->metadata = new Metadata();// // Time attribute is always \DateTime object!// $gpx_file->metadata->time = new \DateTime();// // Description of GPX file// $gpx_file->metadata->description = "My pretty awesome GPX file, created using phpGPX library!";// // Adding link created before to links array of metadata// // Metadata of GPX file can contain more than one link// $gpx_file->metadata->links[] = $link;