admin管理员组

文章数量:1387354

There are lots of gpx data out there. using google map, Kml data loading and displaying is easy. the code is:

var ctaLayer = new google.maps.KmlLayer('.kml');
        ctaLayer.setMap(this.mMap);

but, I want to make a gpx data display on the google map. I know I can use babel, the converter, it's a software not library.

I have no idea what's the best way to display gpx data on google map. making converter using php(duplicated file), or making loader using javascript... --;

my current programming language is php for server.

any good idea or ment please~~~

There are lots of gpx data out there. using google map, Kml data loading and displaying is easy. the code is:

var ctaLayer = new google.maps.KmlLayer('http://gmaps-samples.googlecode./svn/trunk/ggeoxml/cta.kml');
        ctaLayer.setMap(this.mMap);

but, I want to make a gpx data display on the google map. I know I can use babel, the converter, it's a software not library.

I have no idea what's the best way to display gpx data on google map. making converter using php(duplicated file), or making loader using javascript... --;

my current programming language is php for server.

any good idea or ment please~~~

Share Improve this question asked Feb 15, 2011 at 13:00 Jinbom HeoJinbom Heo 7,41014 gold badges55 silver badges60 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

You can feed GPX files to the KmlLayer constructor you have on your question. The code below worked for me:

function initialize() {

    var latlng = new google.maps.LatLng(40.73, -111.93);
    var myOptions = {
        zoom: 10,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    var ctaLayer = new google.maps.KmlLayer('http://siteyoucontrol./lake-gpx.xml');

    ctaLayer.setMap(map);
}

I have two suggestions, both require some work on your side. OpenLayers is a javascript mapping API that includes a GPX reader, you could possibly use OpenLayers (with Google as a base map) or just use the GPX format reader. Alternately, you could use the OGR library mand line utility ogr2ogr to convert from GPX to KML, possibly setting up a web service to do so. It would be easy to wrap the mand line call in a PHP script that could retrieve a GPX file by URL and convert it into KML and return the resulting KML.

I propose a very simple way to do this: perform an AJAX request to load the GPX file from Javascript, then parse it (very staightforward using jQuery) and create a polyline to display on the Google map.

More details and live example here: Display GPX tracks using Google Maps API (works with Google Maps API v3).

本文标签: phpgoogle map gpx loadinghow toStack Overflow