简体   繁体   English

谷歌地图gpx加载,如何?

[英]google map gpx loading, how to?

There are lots of gpx data out there.那里有很多 gpx 数据。 using google map, Kml data loading and displaying is easy.使用谷歌地图,Kml数据加载和显示很容易。 the code is:代码是:

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

but, I want to make a gpx data display on the google map.但是,我想在谷歌地图上显示一个 gpx 数据。 I know I can use babel , the converter, it's a software not library.我知道我可以使用babel转换器,它是一个软件而不是库。

I have no idea what's the best way to display gpx data on google map.我不知道在谷歌地图上显示 gpx 数据的最佳方式是什么。 making converter using php(duplicated file), or making loader using javascript... --;使用 php(重复文件)制作转换器,或使用 javascript 制作加载器... --;

my current programming language is php for server.我目前的编程语言是用于服务器的 php。

any good idea or comment please~~~有什么好的建议或者意见~~~

You can feed GPX files to the KmlLayer constructor you have on your question.您可以将 GPX 文件提供给您对问题的 KmlLayer 构造函数。 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.com/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. OpenLayers是一个包含 GPX 阅读器的 javascript 映射 API,您可以使用 OpenLayers(以 Google 作为基本地图)或仅使用 GPX 格式阅读器。 Alternately, you could use the OGR library command line utility ogr2ogr to convert from GPX to KML, possibly setting up a web service to do so.或者,您可以使用OGR库命令行实用程序ogr2ogr从 GPX 转换为 KML,可能需要设置一个 Web 服务来执行此操作。 It would be easy to wrap the command line call in a PHP script that could retrieve a GPX file by URL and convert it into KML and return the resulting KML.将命令行调用包装在 PHP 脚本中很容易,该脚本可以通过 URL 检索 GPX 文件并将其转换为 KML 并返回结果 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.我提出了一个非常简单的方法来做到这一点:执行 AJAX 请求以从 Javascript 加载 GPX 文件,然后解析它(使用 jQuery 非常简单)并创建一条折线以显示在 Google 地图上。

More details and live example here: Display GPX tracks using Google Maps API (works with Google Maps API v3).更多详细信息和现场示例: 使用 Google Maps API 显示 GPX 轨迹(与 Google Maps API v3 一起使用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM