PHPackages                             lachlanhickey/gps-track-converter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. lachlanhickey/gps-track-converter

ActiveLibrary

lachlanhickey/gps-track-converter
=================================

A package to convert GPX, KMZ, and KML files to LineString

v1.0.3(1y ago)09MITPHPPHP ^7.4|^8.0

Since May 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/lachlanhickey/gps-track-converter)[ Packagist](https://packagist.org/packages/lachlanhickey/gps-track-converter)[ RSS](/packages/lachlanhickey-gps-track-converter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

GPS Track Converter
===================

[](#gps-track-converter)

A PHP package for converting GPX, KMZ, and KML files to LineString format with distance calculations and route densification.

Features
--------

[](#features)

- Convert GPX, KMZ, and KML files to LineString format
- Automatic file type detection
- Densify LineString to have points at regular intervals (default: 100 meters)
- Calculate total distance of the track
- Calculate distance from start for each point
- Compatible with Laravel and other PHP frameworks

Requirements
------------

[](#requirements)

- PHP 7.4 or 8.0+
- SimpleXML extension
- ZIP extension
- Composer

Installation
------------

[](#installation)

```
composer require lachlanhickey/gps-track-converter
```

Or add this to your `composer.json` and run `composer install`:

```
{
    "require": {
        "lachlanhickey/gps-track-converter": "^1.0"
    }
}
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use App\GpsTrackConverter;

$converter = new GpsTrackConverter();
$result = $converter->convert('/path/to/track.gpx');

// Access results
$points = $result->points; // Array of point objects
$totalDistance = $result->totalDistance; // in meters

// Access start and finish locations directly
$startPoint = $result->start_location;
$finishPoint = $result->finish_location;

echo "Route starts at: {$startPoint->lat}, {$startPoint->lon}";
echo "Route ends at: {$finishPoint->lat}, {$finishPoint->lon}";
echo "Total distance: {$result->totalDistance} meters";

// Access individual point data
$firstPoint = $points[0];
echo "First point: Lat: {$firstPoint->lat}, Lon: {$firstPoint->lon}, " .
     "Elevation: {$firstPoint->elevation}, " .
     "Distance from start: {$firstPoint->distance_from_start} meters, " .
     "Distance from previous: {$firstPoint->distance_from_previous} meters";

// Calculate average segment length
$totalSegments = count($points) - 1;
$averageSegmentLength = 0;

if ($totalSegments > 0) {
    $totalSegmentLength = 0;
    foreach ($points as $point) {
        $totalSegmentLength += $point->distance_from_previous;
    }
    $averageSegmentLength = $totalSegmentLength / $totalSegments;
}

echo "Average segment length: {$averageSegmentLength} meters";
```

### Laravel Controller Example

[](#laravel-controller-example)

```
namespace App\Http\Controllers;

use App\GpsTrackConverter;
use Illuminate\Http\Request;

class GpsTrackController extends Controller
{
    public function convert(Request $request)
    {
        $request->validate([
            'file' => 'required|file|mimes:gpx,kml,kmz',
        ]);

        $file = $request->file('file');
        $filePath = $file->getPathname();
        $fileType = $file->getClientOriginalExtension();

        try {
            $converter = new GpsTrackConverter();
            $result = $converter->convert($filePath, $fileType);

            return response()->json([
                'success' => true,
                'data' => $result
            ]);
        } catch (\Exception $e) {
            return response()->json([
                'success' => false,
                'message' => $e->getMessage()
            ], 400);
        }
    }
}
```

Return Format
-------------

[](#return-format)

The converter returns an object with the following structure:

```
stdClass Object (
    [points] => Array (
        [0] => stdClass Object (
            [lat] => 47.123456
            [lon] => 8.123456
            [elevation] => 1234.5
            [distance_from_start] => 0 // in meters
            [distance_from_previous] => 0 // First point has 0 distance from previous
        )
        [1] => stdClass Object (
            [lat] => 47.124567
            [lon] => 8.124567
            [elevation] => 1235.5
            [distance_from_start] => 100.0 // in meters
            [distance_from_previous] => 100.0 // in meters
        )
        // More points...
    )
    [totalDistance] => 12345.67 // Total distance in meters
    [originalPointCount] => 120
    [densifiedPointCount] => 245
    [start_location] => stdClass Object (
        [lat] => 47.123456
        [lon] => 8.123456
        [elevation] => 1234.5
        [distance_from_start] => 0
        [distance_from_previous] => 0
    )
    [finish_location] => stdClass Object (
        [lat] => 47.129876
        [lon] => 8.129876
        [elevation] => 1240.5
        [distance_from_start] => 12345.67
        [distance_from_previous] => 100.0
    )
)
```

Supported File Formats
----------------------

[](#supported-file-formats)

### GPX

[](#gpx)

Extracts coordinates from:

- Track points (`trkpt`)
- Route points (`rtept`)
- Waypoints (`wpt`)

### KML

[](#kml)

Extracts coordinates from:

- LineString elements
- Point elements

### KMZ

[](#kmz)

Automatically extracts and processes the KML file from the KMZ archive.

Densification
-------------

[](#densification)

The package can densify routes to have points at regular intervals. This is useful for:

- Creating smoother visualizations
- Ensuring consistent data for analysis
- Generating intermediate points for animations

By default, densification creates points every 100 meters along the route.

Error Handling
--------------

[](#error-handling)

The converter throws exceptions for:

- Unsupported file types
- Files with no coordinates
- Invalid file formats
- KMZ files without a KML inside

License
-------

[](#license)

MIT

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance49

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

377d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c3acad65aa9881b693965139916c774ae7a46e2644f66c4274af78e42d3135ff?d=identicon)[lachlanhickey](/maintainers/lachlanhickey)

---

Top Contributors

[![lachlanhickey](https://avatars.githubusercontent.com/u/3625525?v=4)](https://github.com/lachlanhickey "lachlanhickey (6 commits)")

### Embed Badge

![Health badge](/badges/lachlanhickey-gps-track-converter/health.svg)

```
[![Health](https://phpackages.com/badges/lachlanhickey-gps-track-converter/health.svg)](https://phpackages.com/packages/lachlanhickey-gps-track-converter)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.6k509.9M17.0k](/packages/laravel-framework)[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k84.2M225](/packages/laravel-horizon)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[stancl/tenancy

Automatic multi-tenancy for your Laravel application.

4.3k6.6M40](/packages/stancl-tenancy)[knuckleswtf/scribe

Generate API documentation for humans from your Laravel codebase.✍

2.3k12.2M45](/packages/knuckleswtf-scribe)[google/cloud

Google Cloud Client Library

1.2k16.2M53](/packages/google-cloud)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
