abduns / laravel-gpx-reader
A Laravel package to read and work with GPX 1.1 files.
Installs: 2
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/abduns/laravel-gpx-reader
Requires
- php: ^8.2
- illuminate/support: ^11.0|^12.0
Requires (Dev)
- orchestra/testbench: ^9.0|^10.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
README
A robust, dependency-free Laravel package to parse and work with GPX 1.1 files. Convert GPX XML into rich, type-safe PHP objects.
Features
- 🚀 GPX 1.1 Support: Fully compliant with the GPX 1.1 schema.
- 📦 No External Dependencies: Uses native PHP XML parsing.
- 🛠Laravel Integration: Includes Facade, Service Provider, and Config.
- 🛡 Type-Safe DTOs: Work with rich PHP objects (
Track,Route,Waypoint) instead of raw arrays or XML. - ✅ Validation: Optional strict mode to ensure GPX validity.
Installation
You can install the package via composer:
composer require abduns/laravel-gpx-reader
Usage
Parsing a GPX file
You can parse a GPX file from a path or a string using the Gpx facade.
use Dunn\GpxReader\Facades\Gpx; // From file $gpx = Gpx::parseFromFile('path/to/file.gpx'); // From string $gpx = Gpx::parseFromString($xmlString);
Working with the GPX Document
The parser returns a Dunn\GpxReader\DTO\GpxDocument object, which mirrors the GPX 1.1 schema.
// Access metadata echo $gpx->creator; echo $gpx->version; if ($gpx->metadata) { echo $gpx->metadata->name; echo $gpx->metadata->desc; echo $gpx->metadata->time?->format('Y-m-d H:i:s'); } // Access Waypoints foreach ($gpx->waypoints as $waypoint) { echo "Waypoint: {$waypoint->name} ({$waypoint->latitude}, {$waypoint->longitude})"; } // Access Routes foreach ($gpx->routes as $route) { echo "Route: {$route->name}"; foreach ($route->points as $point) { echo " - Point: {$point->latitude}, {$point->longitude}"; } } // Access Tracks foreach ($gpx->tracks as $track) { echo "Track: {$track->name}"; foreach ($track->segments as $segment) { foreach ($segment->points as $point) { echo " - Point: {$point->latitude}, {$point->longitude}, Ele: {$point->elevation}"; } } }
Configuration
You can publish the config file with:
php artisan vendor:publish --tag="gpx-config"
The config file allows you to configure strict mode and timezone.
return [ 'strict_mode' => true, // Throw exceptions for invalid GPX structure 'timezone' => 'UTC', ];
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.