loskoderos/gpx-php
Composer 安装命令:
composer require loskoderos/gpx-php
包简介
GPX library for PHP
README 文档
README
GPX library for PHP
What is this?
GPX (GPS Exchange Format) is a de facto standard file format for sharing GPS tracks in the travel/adventure/overland circles. The library contains a GPX reader and writer allowing you to easily work with GPX files in PHP applications.
What is GPX used for? In general its a common format to share routes and tracks recorded by GPS devices. While travelling you can keep recording your current location with your GPS device and then export that track in the GPX format to other software or share it with others.
More information about the GPX format: https://en.wikipedia.org/wiki/GPS_Exchange_Format http://www.topografix.com/GPX/1/1
Installation
GPX-PHP is still under development, however if you want to try it out you can easily install it with Composer:
composer config minimum-stability dev
composer require loskoderos/gpx-php:dev-master
Reading GPX files
Sample code to read contents of the GPX file and list point coordinates.
<?php use LosKoderos\GPX\GPXReader; require '../vendor/autoload.php'; $reader = new GPXReader(); $gpx = $reader->readFromFile('garmin.gpx'); foreach ($gpx->routes as $route) { echo sprintf("[%0.8f, %0.8f] %s\n", (float) $route->points[0]->latitude, (float) $route->points[0]->longitude, $route->name); }
Writing GPX files
The library contain model representing each of the entities found in the GPX specification. You can create a GPX by adding elements one by one.
<?php use LosKoderos\GPX\GPXWriter; use LosKoderos\GPX\Model\GPX; use LosKoderos\GPX\Model\Track; use LosKoderos\GPX\Model\TrackSegment; use LosKoderos\GPX\Model\Waypoint; require '../vendor/autoload.php'; $gpx = new GPX(); $gpx->creator = 'gpx-php'; $segment = new TrackSegment(); $waypoint = new Waypoint(); $waypoint->latitude = 50.0583; $waypoint->longitude = 19.8006; $waypoint->time = new \DateTime("+1 minutes"); $segment->points->add($waypoint); $waypoint = new Waypoint(); $waypoint->latitude = 50.0584; $waypoint->longitude = 19.8007; $waypoint->time = new \DateTime("+2 minutes"); $segment->points->add($waypoint); $waypoint = new Waypoint(); $waypoint->latitude = 50.0588; $waypoint->longitude = 19.8009; $waypoint->time = new \DateTime("+3 minutes"); $segment->points->add($waypoint); $track = new Track(); $track->segments->add($segment); $gpx->tracks->add($track); $writer = new GPXWriter(); echo $writer->writeToFile($gpx, 'out.gpx');
Other option to create a GPX is simply by passing GPX as array to the writer.
<?php use LosKoderos\GPX\GPXWriter; use LosKoderos\GPX\Model\GPX; require '../vendor/autoload.php'; const DATA = [ 'version' => '1.1', 'creator' => 'gpx-php', 'metadata' => [ 'name' => 'Sample track', 'author' => [ 'name' => 'Johnnie Walker', 'email' => ['id' => 'johnie', 'domain' => 'walker.tld'] ] ], 'tracks' => [ [ 'name' => 'Track 1', 'segments' => [ [ 'points' => [ [ 'latitude' => 50.0583, 'longitude' => 19.8006, 'time' => new \DateTime("+1 minutes") ], [ 'latitude' => 50.0584, 'longitude' => 19.8007, 'time' => new \DateTime("+2 minutes") ], [ 'latitude' => 50.0588, 'longitude' => 19.8009, 'time' => new \DateTime("+3 minutes") ], ] ] ] ] ] ]; $gpx = new GPX(DATA); $writer = new GPXWriter(); echo $writer->writeToString($gpx);
Contributing
Contributions are welcome, please submit a pull request.
License
MIT
loskoderos/gpx-php 适用场景与选型建议
loskoderos/gpx-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 403 次下载、GitHub Stars 达 32, 最近一次更新时间为 2023 年 01 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 loskoderos/gpx-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 loskoderos/gpx-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 403
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 32
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-01-03
