https://github.com/ixnode/php-gpx-reader
A versatile library for reading GPX files and efficiently retrieving GPS coordinates based on timestamps.
https://github.com/ixnode/php-gpx-reader
Last synced: 4 months ago
JSON representation
A versatile library for reading GPX files and efficiently retrieving GPS coordinates based on timestamps.
- Host: GitHub
- URL: https://github.com/ixnode/php-gpx-reader
- Owner: ixnode
- License: mit
- Created: 2024-12-07T18:28:53.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-07T23:37:26.000Z (over 1 year ago)
- Last Synced: 2025-07-26T22:18:09.205Z (11 months ago)
- Language: PHP
- Size: 184 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP GPX Reader
[](https://github.com/ixnode/php-gpx-reader/releases)
[](https://github.com/ixnode/php-gpx-reader/releases)

[](https://www.php.net/supported-versions.php)
[](https://phpstan.org/user-guide/rule-levels)
[](https://phpunit.de)
[](https://www.php-fig.org/psr/psr-12/)
[](https://github.com/phpmd/phpmd)
[](https://github.com/rectorphp/rector)
[](https://github.com/ixnode/php-api-version-bundle/blob/master/LICENSE)
> PHP GPX Reader - A versatile library for reading GPX files and efficiently retrieving GPS coordinates based on timestamps.
The PHP GPX Reader is a lightweight and powerful tool to find the nearest GPS coordinate from a GPX file based on a
specific timestamp. While it's perfect for photo geotagging (e.g., matching photo timestamps to GPS data), the tool
can be used in many other scenarios where time-based GPS data needs to be processed.
## 1. Features
* Reads GPX files and retrieves the closest GPS coordinate to a given timestamp.
* Efficiently handles GPX tracks with multiple points.
* Allows precise time matching to find the nearest location.
* Supports time offset adjustments for scenarios where the reference time is inaccurate.
* Flexible and easy to integrate for different use cases.
## 2. Usage
```php
use Ixnode\PhpGpxReader\GpxReader;
...
$gpxReader = new GpxReader($fileObject);
/* Set time gap from camera time: The clock goes ahead. */
$gpxReader->setTimeGapFromString('-00:13:00');
/* Set (real) time to search. */
$gpxReader->setDateTimeFromString('2024-05-05 13:04:16', new DateTimeZone(Timezones::EUROPE_BERLIN));
/* Get the closest coordinate from GPX file. */
$coordinate = $gpxReader->getCoordinate();
/* Time difference to next point. */
print $gpxReader->getTimeDifference();
// (int) 5
/* Latitude to the closest point. */
print $coordinate->getLatitude();
// (float) 47.099262
/* Longitude to the closest point. */
print $coordinate->getLongitude();
// (float) 9.942202
/* Google maps link. */
print $coordinate->getLinkGoogle().PHP_EOL;
// (string) https://www.google.de/maps/place/47.099262+9.942202
```
## 3. Installation
```bash
composer require ixnode/php-gpx-reader
```
```bash
vendor/bin/php-gpx-reader -V
```
```bash
0.1.0 (2024-12-07 19:00:00) - Björn Hempel
```
## 4. Command line tool
### 4.1 Search for the closest point with given taken time
> Search for the closest point within a gpx file with given date and camera time gap.
```bash
bin/console gpx:read data/gpx/2024-05-05.gpx --date="2024-05-05 13:04:16" --gap="\-00:13:00"
```
or within your composer project:
```bash
vendor/bin/php-gpx-reader gpx:read data/gpx/2024-05-05.gpx --date="2024-05-05 13:04:16" --gap="\-00:13:00"
```
```bash
Time to search: 05.05.2024 10:51:16 UTC
Time difference: 5s
Coordinate: lat=47.099262; lon=9.942202
Coordinate: 47.099262, 9.942202
Google link: https://www.google.de/maps/place/47.099262+9.942202
```
### 4.2 Search for the closest point with given image (to read the taken time)
> Search for the closest point within a gpx file with given date and camera time gap.
```bash
bin/console gpx:read data/gpx/2024-05-05.gpx --image="data/image/example-basic.jpg" --gap="\-00:13:00"
```
or within your composer project:
```bash
vendor/bin/php-gpx-reader gpx:read data/gpx/2024-05-05.gpx --image="data/image/example-basic.jpg" --gap="\-00:13:00"
```
```bash
Time to search: 05.05.2024 10:51:17 UTC
Time difference: 4s
Coordinate: lat=47.099251; lon=9.942342
Coordinate: 47.099251, 9.942342
Google link: https://www.google.de/maps/place/47.099251+9.942342
```
## 5. Library development
```bash
git clone git@github.com:ixnode/php-gpx-reader.git && cd php-gpx-reader
```
```bash
composer install
```
```bash
composer test
```
## 6. License
This library is licensed under the MIT License - see the [LICENSE](/LICENSE) file for details.