abduns/laravel-gpx-reader 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

abduns/laravel-gpx-reader

最新稳定版本:v2.0.0

Composer 安装命令:

composer require abduns/laravel-gpx-reader

包简介

A Laravel package to read and work with GPX 1.1 files.

README 文档

README

Latest Version on Packagist License

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.

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-08