In my last BLOG posting "Google Maps API and XSLT" I made use of a file in ".kml" format consisting of my interesting running routes abroad of Germany.
In this posting I want to show how I extracted these routes from gmap-pedometer.com
and converted them to a single .kml file, of course by a stylesheet.
The generated .kml file has an interesting feature the conversion process inserts, if requested:
If the URL where the .kml file will be located finally is provided, then the generated file does automatically redirect to its maps.google.com display!
If you want to try out first, just click on this example (the reason why suffix ".kml.xml" is needed will be described below) -- works for all BIG5 browsers:
(on the left side the directory of routes is opened, clicking on any hightlights and centers that route in map display, regardless of zoom level)
What is gmap-pedometer.com?
It is a website for entering routes, either for car, bycicle or runners (like me).
The length of the route is determined, an altitude display is available, and most importantly, the routes can be stored.
After storing the routes are available under a simple URL like http://www.gmap-pedometer.com/?r=1156387
Currently more than 5.734.000 routes have been stored by all users.
How to extract a single route from gmap-pedometer.com?
Unfortunately gmap-pedometer.com is based on v2 API -- I hope that Google will migrate to v3 before EOS for v2.
It is to be used as a bookmarklet
Since it makes heavy use of undocumented Google maps API calls, I just used it and did not try to do that part myself.
The extracted GPX files (1156387.gpx
for the previously mentioned route sample) is an XML file itself.
Why doing my own gpxs2kml.xsl converter and not use recommended "GPS Visualizer"?
There are many GPX format converers for GPS data, but all that I found to be capable of generating Google KML format did it 1-to-1.
I wanted to convert many GPX files into a single .kml file, and therefore created stylesheet gpxs2kml.xsl .
Why the .kml.xml suffix?
A KML file is fine to have for display in Google maps or Google earth.
It is an XML file, and therefore a xml-stylesheet processing instruction could do "something useful" when opened in a browser.
The "something useful" I made happen is "display route in maps.google.com" by just opening it in the browser.
Some browsers do not process the processing instruction if the suffix is not ".xml", therefore I used ".kml.xml" to indicate what we have.
How to redirect to maps.google.com with a processing-instruction?
The URL to be redirected to is "http://maps.google.de/maps?q=yourURL".
The simple trick for redirection is to generate a small HTML page consisting of a "/html/head/meta" element with "refresh" http-equiv attribute.
The stylesheet doing the redirection is redirect.gmap.xsl
and it invoked this way (for above mentioned sample link
<?xml-stylesheet type="text/xsl" href="redirect.gmap.xsl?http://stamm-wilbrandt.de/en/blog/gmap/interesting.kml.xml">
And this is stylesheet redirect.gmap.xsl:
After having extracted the GPX files (these are XML files as well) as described above, file interesting.xml
specifies what to convert:
$ xsltproc gpxs2kml.xsl interesting.xml > interesting.kml.xml
And this is gpxs2kml.xsl
, it converts the GPX routes to KML Placemarks more or less straight-forward: