Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gpx #374

Open
dennisbusk opened this issue Jan 22, 2021 · 1 comment
Open

gpx #374

dennisbusk opened this issue Jan 22, 2021 · 1 comment

Comments

@dennisbusk
Copy link

Hi...
Great product.

I was just wondering if it possible to load a gpx file and show a route on the map?

@bradcornford
Copy link
Owner

Hi,

This package doesn't natively support this, however I'm sure you can achieve this using PHP itself, you could read the GPX file, and iterate over each of the found lat/longs and draw polylines from the initial point and the next. Something along the lines of the following:

Mapper::map(53.381128999999990000, -1.470085000000040000);
$gpx = simplexml_load_file("test.gpx");
$points = [];

foreach ($gpx->trk as $trk) {
    foreach($trk->trkseg as $seg) {
        foreach($seg->trkpt as $pt) {
            $points[] = [
                'lat' => $pt["lat"], 
                'lon' => $pt["lon"]
            ];
        }
    }
}
unset($gpx);

$previousPoint = null;

foreach ($points as $point) {
    if ($previousPoint !== null) {
        Mapper::polyline([['latitude' =>  $previousPoint['lat'], 'longitude' => $previousPoint['lon']], ['latitude' => $point['lat'], 'longitude' => $point['lon']]]);
    }
    $previousPoint = $point;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants