Tuesday, July 26, 2005

Using XSL to Transform Google Earth (KML) and GPX to Google Maps API

I noticed that Google Earth ships with something called GPSBabel (and my old friend expat.dll). Now I knew almost nothing about the world of GPS devices but I soon found that there are (too) many GPS file formats in the world. GPX seems to have become the de-facto XML standard but because of the wide variety of GPS hardware there are still plenty of different plain text file formats kicking about. GPSBabel is GPS format conversion software. I noticed that Google Earth can load GPX files! I found that using free GPS conversion utilities like GPS utility, G7toWin and GPSBabel I can pretty much convert anything I find on the net into a format that I can import in Google Earth (the freeware version!).

Secondly, I thought I could write an XSL to convert GPX to KML and vice versa but I found to my delight that GPSBabel has provisional support for converting GPX to KML, so I can leave the XSL stylesheet to someone who really needs to do it.

All this is good so far but what if I want to put the route of a walk on my website using Google Maps API. How difficult is it to convert KML (or GPX for that matter) into the Google Maps API. I wrote two stylesheets that generate the Google Maps JavaScript that make a map containing a "GPolyline" of a route. I used a GPS text file of walk around the Lake District in Cumbria (in England). Surprisingly it is *much* easier to transform GPX to Google Maps than the KML format. My conclusion would be if you're veering towards using Google Earth professionally then don't throw away your GPX files until someone writes an XSL to convert them back from KML format (you need an escape strategy).

Get your Google Maps API key here.

KML to Google Maps API XSL Stylesheet.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method = "text" version="1.0" omit-xml-declaration="yes" />

<xsl:template match="/">
<xsl:apply-templates select="*[local-name()='kml']/*[local-name()='Document']"/>
</xsl:template>

<xsl:template match="*[local-name()='kml']/*[local-name()='Document']">
<xsl:apply-templates select="*[local-name()='Folder']"/>
</xsl:template>

<xsl:template match="*[local-name()='Folder']">
<xsl:apply-templates select="*[local-name()='Folder' or local-name()='Placemark']"/>
</xsl:template>

<xsl:template match="*[local-name()='Placemark']">
<xsl:apply-templates select="*[local-name()='MultiGeometry']"/>
</xsl:template>

<xsl:template match="*[local-name()='MultiGeometry']">
<xsl:apply-templates select="*[local-name()='LineString']"/>
</xsl:template>

<xsl:template match="*[local-name()='LineString']">
<xsl:apply-templates select="*[local-name()='coordinates']"/>
</xsl:template>

<xsl:template match="*[local-name()='coordinates']">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml"&gt;
&lt;head&gt;
&lt;meta http-equiv="content-type" content="text/html; charset=UTF-8"/&gt;
&lt;title&gt;Google Maps API Example - overlay&lt;/title&gt;
&lt;style type="text/css"&gt;
v\:* {
behavior:url(#default#VML);
}
&lt;/style&gt;
&lt;script src="http://maps.google.com/maps?file=api&amp;v=1&amp;key=ABQIAAAA4Wxrd1ZmQfRHvggZWM0QkxSywvohUEBj468j1bHLctjAi9H1aRTgpH5EJsqp8F3DqOP3spOw36wc2A" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
//&lt;![CDATA[
function onLoad() {
var map = new GMap(document.getElementById("map"));
map.setMapType(G_HYBRID_TYPE)
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
<xsl:call-template name="firstPoint">
<xsl:with-param name="str" select="normalize-space(.)"/>
</xsl:call-template>
var points = [];
<xsl:call-template name="split">
<xsl:with-param name="str" select="normalize-space(.)"/>
</xsl:call-template>
map.addOverlay(new GPolyline(points));
}
//]]&gt;
&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="onLoad()"&gt;
&lt;div id="map" style="width: 500px; height: 300px"&gt;&lt;/div&gt;
&lt;div id="message"&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</xsl:template>

<xsl:template name="firstPoint"><xsl:param name="str"/>
<xsl:if test="contains($str,' ')"> map.centerAndZoom(new GPoint(<xsl:value-of select="substring-before(substring-before($str,' '),',0')"/>), 5);
</xsl:if>
</xsl:template>

<xsl:template name="split"><xsl:param name="str"/>
<xsl:choose><xsl:when test="contains($str,' ')"> points.push(new GPoint(<xsl:value-of select="substring-before(substring-before($str,' '),',0')"/>));
<xsl:call-template name="split">
<xsl:with-param name="str" select="normalize-space(substring-after($str,' '))"/>
</xsl:call-template></xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</xsl:template>

</xsl:stylesheet>
GPX to Google Maps API XSL Stylesheet

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method = "text" version="1.0" />

<xsl:template match="/">
<xsl:apply-templates select="*[local-name()='gpx']"/>
</xsl:template>

<xsl:template match="*[local-name()='gpx']">&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml"&gt;
&lt;head&gt;
&lt;meta http-equiv="content-type" content="text/html; charset=UTF-8"/&gt;
&lt;title&gt;Google Maps API Example - overlay&lt;/title&gt;
&lt;style type="text/css"&gt;
v\:* {
behavior:url(#default#VML);
}
&lt;/style&gt;
&lt;script src="http://maps.google.com/maps?file=api&amp;v=1&amp;key=ABQIAAAA4Wxrd1ZmQfRHvggZWM0QkxSywvohUEBj468j1bHLctjAi9H1aRTgpH5EJsqp8F3DqOP3spOw36wc2A" type="text/javascript"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
//&lt;![CDATA[
function onLoad() {
var map = new GMap(document.getElementById("map"));
map.setMapType(G_HYBRID_TYPE)
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
var points = [];
<xsl:apply-templates select="*[local-name()='trk']/*[local-name()='trkseg']/*[local-name()='trkpt']"/>
map.addOverlay(new GPolyline(points));
}
//]]&gt;
&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="onLoad()"&gt;
&lt;div id="map" style="width: 500px; height: 300px"&gt;&lt;/div&gt;
&lt;div id="message"&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</xsl:template>

<xsl:template match="*[local-name()='trk']/*[local-name()='trkseg']/*[local-name()='trkpt']">
<xsl:if test="position() = 1">
map.centerAndZoom(new GPoint(<xsl:value-of select="@lon"/>, <xsl:value-of select="@lat"/> ), 5);
</xsl:if>
points.push(new GPoint(<xsl:value-of select="@lon"/>, <xsl:value-of select="@lat"/> ));
</xsl:template>


</xsl:stylesheet>

Google Earth

Google Maps

Also a few other miscellaneous things I've noticed recently about Google Earth and it's sister Google Maps.

  • The user-agent for Google Earth is kh_unk/unk
  • Google Maps core functionality isn't really that AJAXy, all the co-ordinates for the map tile URLs are calculated in the client side JavaScript (granted, it is still extremely clever)
  • Both Google Earth and Google Maps use the same server for the keyhole satellite maps: kh.google.com
  • Google Maps also uses a server called: mt.google.com, I'm guessing the "mt" stands for map tiles
  • Both mt and kh servers run Linux! Hurray!
  • The "web server" on kh is running Keyhole Server 2.4
  • The "web server" on mt is running something called "tfe" - (educated guess, does the "t" stand for telemetry?)
  • There is a Google Earth server hardware available for industry but no mention anywhere of how much it will cost, I suspect if you have to ask you can't afford it!

83 comments:

Mark McLaren said...

This is extremely interesting! How do you use these? If I have a kml or gpx file that I want to display on a google map, how would I do this using your templates?
Note: Comment imported. Original by Lisa Harper at 2005-08-02 20:44

Mark McLaren said...

Hi Lisa,

The above documents are XSL stylesheets therefore to use them you need an XSLT processor.

If you are happy with command line utilities I would recommend something like Sablotron.

Otherwise you could download a free utility like XML Cooktop or XML Spy home edition.





If you want more information about XSL then I wrote an blog entry called Learning XSLT resources that you may find useful.





If you'd like a more detailed explanation of how to use XSL stylesheets then let me know.


Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2005-08-02 22:25

Mark McLaren said...

If you were using Sablotron you would invoke the XSL engine thus:

sabcmd gpx2gmaps.xsl myfile.gpx outfileGPX.html



OR

sabcmd kml2gmaps.xsl myfile.kml outfileKML.html


Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2005-08-02 22:39

Mark McLaren said...

How about a conversion from kml to gpx? I've been looking all over for something like this.
Note: Comment imported. Original by exssnrg at 2005-08-07 04:02

Mark McLaren said...

I believe GPSBabel has provisional support for converting GPX to KML.



To convert KML to GPX properly would require a KML DTD or XML Schema, this hasn't been released yet as GoogleEarth is still only in BETA!


Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2005-08-07 13:46

Mark McLaren said...

Hey Mark,



I have a great use for your style, but I can't figure out how to get it working, I tried the sablotron utility, as well as the two IDEs, but whenever I try to generate the html with my KML (~800k) I always get an empty html file.



Any advice?
Note: Comment imported. Original by Jason McGuirk at 2005-08-15 20:27

Mark McLaren said...

Could be anything, if you could put the KML on a website somewhere and let me have a look at it, it might help.





I hope this isn't a stupid question but could you confirm it is a KML file and *not* a KMZ file you are trying to work with? KMZ's can be unzipped (using WinZip etc.) into KML if that is the case.


Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2005-08-15 22:05

Mark McLaren said...

Yeah, I'm for sure using a KML file.



This is the one I'm trying to use:



http://econbank.com/SF.kml



Thanks for taking a look :)
Note: Comment imported. Original by Anonymous at 2005-08-15 22:31

Mark McLaren said...

This is very interesting, I read about it the other day… It said something about the main difference between GML and KML is that in KML you have the ability to redefine the XML Schema that makes up the KML document. I’ve never seen it before (but then I’m relatively new to Google Earth) but that is what is happening inside your document.





For example in a “default�? schema document you would have lots of <Placemark> elements, in your example a new type of <Placemark> element called <S_CA_San_Francisco_Bay_Area_N_ISSSSSSSS> has been defined to be used instead. The ability to redefine the element names internally in an XML document makes it a little tricky to write XSL stylesheets for.





I don’t have time to do it now, as it is 11:30pm and I am going to bed, but I will have a look at this tomorrow if you like. I think you could create a Google Maps API GPolyline for each area defined, but you couldn’t have all these areas defined in a single Google Maps HTML document, it would be enormous and probably would slow your browser to a virtual standstill.




Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2005-08-15 23:33

Mark McLaren said...

Here's the article I found the "schema constructs" concept in.



GML FAQ for RSS Geeks and others
Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2005-08-15 23:37

Mark McLaren said...

Yeah, I've tried rendering the GPolyLines using just the points but its a hassle and I've got a lot of data to map. Yeah, it takes about 15-30 seconds to map on a lower end machine, and it's fairly laggy. But I'd like to produce it anyways, if you feel up for it, I'd be eternally grateful :)
Note: Comment imported. Original by Jason McGuirk at 2005-08-16 00:23

Mark McLaren said...

Hi Jason,



As promised, I had a look at that KML file and have created an XSL stylesheet to extract the co-ordinates into an array that JavaScript can use. I then added the necessary extra Google Maps JavaScript stuff by hand (obviously you’ll need you own Google Maps API key).





The HTML file is ~850Kb unzipped, amazingly it actually renders in the browser but is extremely slow. This version is unabridged but you might get something a little faster if you are willing to discard some of the co-ordinate points.





I’ve zipped the XSL and HTML.





Perhaps the XMaps Extension Library might make it possible to achieve something a little more sophisticated.





Cheers,





Mark


Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2005-08-16 19:41

Mark McLaren said...

Thanks a lot Mark,



Works perfectly and I love your API extension already, brilliant.



Here's a screenshot of the final product (the neighborhoods of san fransisco and surronding areas) for use on your website:



http://www.ocf.berkeley.edu/~jmcguirk/BayAreaX.jpg



Thanks again for your help!



- Jason
Note: Comment imported. Original by Jason S McGuirk at 2005-08-17 00:04

Mark McLaren said...

Hello,



I Like your script, but it's to dificult for me. Can you make it clear step by sptep?



Thank you!
Note: Comment imported. Original by Marco website: http://www.marcowagemakers.nl at 2005-10-14 23:51

Mark McLaren said...

Hi Marco,



I'm very happy to help you, it would be easier for me if you could be a bit more specific about what you don't understand.





All you need to transform a GPX/KML file into a Google Maps html file is an XSLT engine and an XSL stylesheet. For example, in Windows the Unicorn XSLT Processor is very easy for a beginner to install. Now you need an XML file, such as:





http://www.travelbygps.com/special/katrina/katrina.gpx





This file is in GPX format. You need to copy the above "GPX to Google Maps API XSL Stylesheet" into a file and call it something like "GPX2GMaps.xsl".





Put all these files into a single directory and create a batch file ("runme.bat") containing something like:





uxt katrina.gpx.xml gpx2gmaps.xsl out.html





and then run the batch file. If all went well you should now have a Google Maps html file which you can install on your web server. Further information about the Google Maps API with examples is available from:





Google Maps API Documentation





Let me know if you need further help,



Mark
Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2005-10-15 08:57

Mark McLaren said...

Someone pointed me to this, so I wrote:



http://www.taral.net/gpx.html



which processes GPX files directly and displays them.
Note: Comment imported. Original by Taral website: http://www.taral.net/ at 2005-11-02 22:18

Mark McLaren said...

Mark, I had a look on this blog and found it extremely useful. I tried to use Unicorn XSLT Processor. It works fine with the gpx example you gave , however I do get the same problem as other people before when using a kml file (empty html document) using your xsl file above.

As I understood it is the problem of the additional info like Placemark and Folder etc. I am happy to delete that info from the kml file but even then it does not seem to work. Did you find any workaround for that problem?

In case it is of any help I placed the kml file in question in this location: www.vennemann.f2s.com/brazil.kml

Thanks a lot, Olav
Note: Comment imported. Original by Olav at 2006-01-08 18:10

Mark McLaren said...

Hi Olav,



The above examples are illustrative rather than a universal solution. In the absence of a DTD for KML (which to the best of my knowledge does not and cannot exist) a universal solution is next to impossible to produce.





I have had a look at your KML and tweaked my XSL stylesheet slightly. There are around 1500 co-ordinates in your KML file so a straight conversion is liable to produce a very slow Google Maps html page.





I have produced a smaller version which only uses every 10th co-ordinate (~150) which should be a lot faster.





See here: http://content.mark-mclaren.info/olav/





HTH, Mark




Note: Comment imported. Original by markmc website: http://cse-mjmcl.cse.bris.ac.uk/blog at 2006-01-08 22:03

Mark McLaren said...

Mark,thank you very much for your fast reply and your effort to modify the SXL stylesheet to suit my file. It works perfectly well.Olav
Note: Comment imported. Original by Olav at 2006-01-09 22:34

Mark McLaren said...

I have a KML file from Google Earth that I am trying to load into a Google Map as an XML file. This is the only place I have found that is even discussing the idea. I have tried the above XSL code and tried the apps suggested to run them together but my output files are blank. Any help?



KML: http://21andover.com/sfmap/sf.kml
Note: Comment imported. Original by speakfree07 at 2006-04-08 09:21

Mark McLaren said...

Hi Speakfree,



The XSL in the example above was tailored to a data set which consisted of long lists of space separated co-ordinates (it is slightly broken!). In your KML file, you only have single co-ordinate sets so I had to tweak the XSL a little (actually the resulting XSL is much simpler).





Due to the way that JavaScript handles HTML I had to massage the XSL output by hand (using Search and Replace in TextPad). I also added the remaining Google Maps API related HTML and JavaScript by hand.





The problem is that you have 336 points on the map which makes it slow to render (especially in IE6). You might want to investigate only adding overlays for the points that would appear within the visible page bounds.





Let me know if you need any further assistance.



This is the XSL

This is the HTML result
Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2006-04-10 10:31

Mark McLaren said...

As I had a bit of time to kill, the following Google Maps page adds only the points that should be visible in the current bounds, not all 336 at once, so it renders faster.



This is the HTML
Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2006-04-10 11:54

Mark McLaren said...

Thank you very much for the help. This definitely works. I used the 2nd one you provided and it still runs a little sluggish (mostly when you zoom out and view all the points). Does it perform any faster/slower when all the data points are in the HTML rather then in an XML file? If I plan on making more maps like this what might you recommend to make this run smoother and not crash viewers' browsers? What if I used a database?
Note: Comment imported. Original by speakfree07 at 2006-04-10 19:13

Mark McLaren said...

When you zoom out it is possible that all the points may be in the visible bounds at certain zoom levels. The thing to do to avoid this is to impose a maximum limit (e.g. 50) but you'd need to warn the user that not all points are displayed at certain zoom levels.





If you want to provide this service for a larger area then you could use a database. You could achieve this effect in a similar way to how the GeoURL rendering works. I use JSP and with JSP/JSTL you could access a database and produce XML quite easily but you might prefer to use PHP, Python, Ruby, Perl or ASP.





e.g. see my entries for:



GeoURL To Google Maps using the Official API



GeoURL To Google Maps using the Official API: Part II


Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2006-04-10 20:25

Mark McLaren said...

One thing I noticed about your code that shows only the markers in the current bounds...if you move the map ever so slightly so that some markers on the edges are moved outside the bounds, but the ones in the center are still there, if you do this repeatedly, watch the marker shadows, they double everytime. Is your code placing markers on top of eachother? This might be a cause of some of the latency/sluggishness as well.
Note: Comment imported. Original by speakfree07 at 2006-04-11 03:19

Mark McLaren said...

You're right, that is happening. We'll get there eventually...



Try this HTML instead


Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2006-04-11 08:46

Mark McLaren said...

That works!! Thank you very much for all your help. My next step is getting these into a database and calling them from there. I have found a tutorial on the subject and we'll see if I run into any snags.
Note: Comment imported. Original by speakfree07 at 2006-04-11 21:14

Mark McLaren said...

Hi Mark,

I have been trying to put a kml file on Google map and tried following the steps you have mentioned but couldnot get it to work.

I am using cooktop to convert my kml to xml but it outputs a blank xml file.. I even tried UXT but the output file is blank again.. I dont know where am I going wrong..

Here is my kml file.. If you can take a look at it http://rungmung.net/Uttaranchal.kml it has a great number of placemarks.. is that a problem..



All I am trying to do is put the contents of this kml online on my Joomla google map component..



thanks..


Note: Comment imported. Original by Amit at 2006-05-20 05:51

Mark McLaren said...

Hi Amit



Uttaranchal.kml is a 3.62 MB file, most of this file is Road data (3.20 MB). The remainder of the file is:





62 Major Waypoints

1363 Minor Waypoints

15 Peak Waypoints





That is rather a lot of data to display in a single Google Maps HTML file without some kind of backend database or application arrangement. With all that data any standalone Google Maps page is likely to be very slow. You may also want different icons for peaks, major and minor waypoints.





I have written some simple XSL [KML2CSV.xsl] for you to extract this data from the KML file into CSV files (I used comma delimiters). To do this I used Google Earth to split your large KML file into three smaller files (and then my XSL above virtually worked).





Major Waypoints, [KML], [CSV]

Minor Waypoints, [KML], [CSV]

Peak Waypoints, [KML], [CSV]





If you look at the other examples on this page, you will see how to use JavaScript arrays with Google Maps. Let me know if you require further help regarding Google Maps.





I'm not sure how you could reuse the road data efficiently and you would definitely need a backend application to serve the road data.





I hope this is useful to you, best wishes, Mark


Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2006-05-20 13:48

Mark McLaren said...

Mark thank you very much for taking the pains on working on my file.. the road data is the key to this map.. is there any way I can use it in an efficient way.. as you can tell, I am a total rookie with google maps..



thanks again.. regards..
Note: Comment imported. Original by Amit at 2006-05-20 19:09

Mark McLaren said...

Hi Amit,



In your KML file you have one MultiGeometry element, this contains 933 LineString elements. Each LineString element is composed of a variable number of co-ordinate value sets. As you have probably worked out by now, each co-ordinate is a point in a path. If you only had a few small paths then you could easily render these in Google Maps using the GPolyline class.



The problem is that you have more than a few (933) and some of them are very long paths indeed. At its widest point your KML file is more than 23000 characters wide, that is a lot of co-ordinates in a single line!



What you need is a backend application for your Google Map that is clever enough to work out exactly which paths of your paths are within the bounding box of the current viewport. I would expect this is likely to be quite sophisticated software. There are likely to be several approaches you could take in doing this.



Clever optimised database backend



One way would be do really clever SQL queries, maths, statistics and optimise the backed database so that you can request the areas around your given viewport. I'm afraid I wouldn't really know where to start with this approach.



Custom tiles



The second approach is still not exactly easy! You could pre-generate a set of custom tiles containing your road data (actually you'd need a set for each magnification setting). Then once you have your graphics files you could incorporate your custom tiles into your Google Map.





I'm afraid I can't think of an easier way at the moment but I'll give it some more thought and let you know if I come up with anything.


Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2006-05-20 20:16

Mark McLaren said...

Thank you Mark.. I think I will try working with the second option for now if I can accomplish it...
Note: Comment imported. Original by Amit at 2006-05-20 21:57

Mark McLaren said...

I just ran into this post by accident and I couldn't help but also suggest another alternative that I have implemented. Parse the GPX file in Javascript. I have a set of objects that can display a GPX file loaded from a server. It does require a relatively recent browser, IE and Firefox work well, and doesn't require any extra server processing.



http://notions.okuda.ca/geotagging/projects-im-working-on/gpx-viewer/


Note: Comment imported. Original by Poco website: http://notions.okuda.ca/geotagging/projects-im-working-on/gpx-viewer/ at 2006-09-27 11:08

Mark McLaren said...

As a Real Estate developer I use Google Earth intensively to structure my geographical database that covers Dallas-Forth Worth and fifty small towns in the area. I have many sources and types of data: rents, land values demographics, plats, surveys, aerial photos, GPS field data etc etc.. Google Earth is great to structure the gepgraphical database but it only exports KSL files and you can not input other maps surveys aerial photos etc. Searching in the internet for a solution to my problem I found Gartrip and it worked wonderfully, Its clean, easy, elegant a superb German product. The only limitation was that it could not import KML files.. I sent a email to Heinrich and in a few days he had the solution which will soon be available to all Gartrip users. This globalized world of us is incredible, you can go as fast as you can think and you can match the power of Google with the wits of a German entrepreneur.. Best of all it all spreads like wildfire and benefits all. I no longer use Garmin Mapsource software, the Google Earth/Gartip solution is much more powerful and useful...



look in gartrip.de
Note: Comment imported. Original by benito medero at 2006-09-29 23:42

Mark McLaren said...

Hi,



I would like to convert a kml file to google map api, I used your style sheet and the processor sabcmd but It gave me an empty file.



Also I would like to know if I need a key to make this work, thanks.
Note: Comment imported. Original by Anonymous at 2006-10-02 15:07

Mark McLaren said...

The reason you got an empty file was probably because there was no match for the pattern "kml/Document/Folder" which the above XSL stylesheet looks for. If you could let me see the KML file in question I could help you tailor an XSL stylesheet for it specifically.





It is difficult (if not impossible) to write an universal KML to Google Maps API XSL stylesheet because KML supports something called "schema constructs". This means it is almost impossible to predetermine the precise structure of a KML file and therefore you never know exactly what elements you are going to encounter inside a KML file (probably too much information for you but you did ask!).





Yes, you will need a Google Maps API key for your Google Maps API pages.


Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2006-10-02 16:33

Mark McLaren said...

Hello, Mark.

Thank you for all the work you put in this topic.

I just made a small conversion in the way you explained to speakfree, and it kind of works. Kind of, because the placemarks seem to be in the right place, but its to much zoomed in. According to my map that is, because when I zoom out, Europe is completely without streets and cities. Have a look at http://www.vamos360.com/test/kml.htm

What you are supposed to see can be seen here: http://maps.google.nl/?ie=UTF8&z=15&ll=53.005049,6.766205&spn=0.017328,0.039911&om=1

a friendly little town in the north of Holland.

Do you know which variable I have to change to make the streets of Europe appear?

Kind regards,

Ronald
Note: Comment imported. Original by Anonymous website: http://www.vamos360.com at 2006-10-14 04:22

Mark McLaren said...

It is good to hear that you find this useful. Apparently additional European mainland maps are supported in GMaps API version 2. In order to view the streets and cities you just need to change from v=1 to v=2 in the GMaps JavaScript URI.





To set a different inital zoom level you can modify the second argument passed to centerAndZoom().




Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2006-10-14 11:37

Mark McLaren said...

Thanx again, Mark.

I can see the streets now, but the place marks don't appear. When I look at the javascript console in firefox, i get these messages:

Error: Expected ',' or '{' but found '*'. Ruleset ignored due to bad selector.

Source File: http://www.vamos360.com/test/kml

Line: 7

and

Error: overlays has no properties

Source File: http://www.vamos360.com/test/kml

Line: 52

Btw, I can't believe that the people at google didn't come up yet with a earth to maps converter.
Note: Comment imported. Original by Ronald website: http://www.vamos360.com at 2006-10-14 16:12

Mark McLaren said...

Hi Ronald,



The above technique was written quite a while ago using GMaps API version 1. GMaps API Version 2 is quite different and in many places there are significant improvements. I have to admit that I have not looked at Version 2 in much detail. It is now easier to calculate if a point should be displayed or not. Unfortunately, you can no longer access the overlays array in version 2 (this was a hack even in version 1). I've re-written your example to take advantage of some Version 2 functionality; as a result it should look a bit shorter.





see a reworked version of your code here





At the moment I clearOverlays and re-add everything every time the page moves. With the API improved and optimized hopefully this might not be a big problem. If you have a very large number of locations to display and this method becomes too slow, we would probably need solve this problem in a different way. Let me know if you need help with this (I'd need to find out more about what version 2 can offer in this regard).





I've also read that you no longer need the stylesheet section, as this should be generated if it is necessary. Due to the use of "schema constructs" KML to Google Maps is not as easy as you might think it should be (in truth GPX to Google Maps is easier).




Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2006-10-14 21:55

Mark McLaren said...

Good news, I managed to find an alternative mechanism to manipulate the Google Maps overlays.





I have re-implemented speakfree's 300+ location example with the Google Maps API Version 2.




Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2006-10-14 23:25

Mark McLaren said...

Wow!, do you ever sleep? ;-) Thanx a lot for this.

I as about to do a crashcourse xml/xsl this week, but I think this is all I need actualy.

However, I also found another way to project the kml data on googlemaps, it can be found

here. The html page uses an xml sheet in this

format as a database. So if the kml file is converted to that format it should have the same output I guess.
Note: Comment imported. Original by Ronald website: http://www.vamos360.com at 2006-10-15 02:06

Mark McLaren said...

I have been trying to convert this file:

http://www.aguntherphotography.com/files/nav/desert-trip.kml but so far no luck.

It contains tracks and links to pictures, so I am wondering if it is even possible to convert this.

I am trying to display it on my site.
Note: Comment imported. Original by Andre website: http://www.aguntherphotography.com at 2006-12-10 21:47

Mark McLaren said...

Hi Andre,



I tweaked the KML (renamed XML) slightly to replace the double quotes in HTML in the CDATA sections with single quotes. Then I wrote the XSL that extracts most of the data and the rest of the JavaScript is added by hand.





The result:





http://cse-mjmcl.cse.bris.ac.uk/desert-trip.html





I hope you find this useful.




Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2006-12-11 22:08

Mark McLaren said...

Hi Mark, I've been trying to use your xsl file and method to convert my kml to html but I've encountered the same empty file problem.



My kml file can be found at http://www.freewebs.com/vin478a/wirelessSG_coverage_1.12.06.kml



I'll be really grateful if you could help me customise a xsl file!
Note: Comment imported. Original by vin478a at 2006-12-20 07:15

Mark McLaren said...

Hi Mark,



your tools seems really great! Unfortunally, I get an empty HTML file too. I am sorry, but the thread above doesn't give me a clue. My KML file is a very simple test and directly saved from Google Earth. What is going wrong? Can you please help me?



http://www.rezept.nl/jorrv4/jorr.kml
Note: Comment imported. Original by Jorr.it at 2006-12-21 09:49

Mark McLaren said...

Sorry I can't seem to access the file.
Note: Comment imported. Original by markmc website: http://cse-mjmcl.cse.bris.ac.uk/blog at 2006-12-22 08:52

Mark McLaren said...

Hi,



You have 183 placemarks. I tweaked the XSL used in the above desert trip but altered the namespace from 2.0 to 2.1. Then it pretty much worked:



wirelessSG_coverage_1.12.06.xsl

wirelessSG_coverage_1.12.06.html
Note: Comment imported. Original by markmc website: http://cse-mjmcl.cse.bris.ac.uk/blog at 2006-12-22 09:58

Mark McLaren said...

Sorry, the file is available again:

http://www.rezept.nl/jorrv4/jorr.kml.

Thanks in advance!
Note: Comment imported. Original by Jorr.it website: http://www.rezept.nl at 2006-12-22 21:26

Mark McLaren said...

> Sorry I can't seem to access the file.



Sorry I placed the file back again.



My main problem is that I don't know how to convert the groundoverlay tag to javascript.
Note: Comment imported. Original by Jorr.it website: http://www.rezept.nl at 2006-12-26 19:21

Mark McLaren said...

I will have a think about it.
Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2006-12-27 21:25

Mark McLaren said...

Google can do it. but I am not sure how. Still thinking about it.
Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2006-12-27 22:35

Mark McLaren said...

Hi,



I have done it!:

http://cse-mjmcl.cse.bris.ac.uk/jorr.html





I studied Google's implementation for a little while and worked out that they were using GIcon to implement KML's groundOverlays. A short while later and I have something similar working. Could I use this example in a future blog entry?





Cheers, Mark


Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2006-12-28 00:22

Mark McLaren said...

I'm having the same problem everyone is having, with no data output with uxt. I have a very simple kml with just a few points, exported with google earth. (eventually of course I'll have a lot more but I'm just starting simple)



I think all of the customizations you've done to your XSL for the community is wonderful - however I think it would be helpful if you could give us a very, very simple example and give us the steps.



i.e.

1) install google earth (latest version)

2) create a placemark somewhere

3) maybe create a line with a couplee of points

4) save as kml

5) convert with xsl



If we could get the kml and xml for steps 4 and 5 this would be very helpful.



Personally, I'm unfamiliar with XSL technology, and I also don't really understand the issue with the changing schemas inherent to KML. What schemas change? How must I change the XSL appropriately?



Thanks for your help.


Note: Comment imported. Original by looper at 2007-02-20 23:04

Mark McLaren said...

Interesting idea Looper. I will give it some thought.
Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2007-02-21 16:23

Mark McLaren said...

is it not possible to just include a kml/kmz file into a web page that accesses the google maps api?
Note: Comment imported. Original by paul at 2007-03-05 22:01

Mark McLaren said...

Wow thats very very impressive!



I'm the owner of the data source (www.haroldstreet.org.uk).

How easy would it be to write a script that takes one of my little gpsu txt files of data and generates the little map image with the track as you have done.



phil
Note: Comment imported. Original by phil newby website: http://www.haroldstreet.org.uk at 2007-04-23 16:53

Mark McLaren said...

Theoretically it should be fairly straightforward also the software will have evolved slightly since I originally wrote this back in July 2005. I would be very happy to help you get things started.



Mark
Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2007-04-24 08:34

Mark McLaren said...

That would be appreciated



However; i'm no programmer and pretty much didn't understand much of the above discussions! i can do simple HTML and am learning a bit of PHP but i think i'm out of my deapth with this.



What would it involve?
Note: Comment imported. Original by phil newby website: http://www.haroldstreet.org.uk at 2007-04-24 09:32

Mark McLaren said...

I will need to revisit this when I get the time, to see if converting the GPSU files has got any easier recently (at the time of the above article GPSBabel did not support it). I will get back to you in a week or so.


Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2007-04-25 08:40

Mark McLaren said...

Cheers
Note: Comment imported. Original by phil newby website: http://www.haroldstreet.org.uk at 2007-04-25 16:16

Mark McLaren said...

Hi there,



Your work on this is amazing, can't thankyou enough!



Unfortunately i'm having the same problem as many, in that i get a blank output file.



the file i'm trying to use can be found at: http://www.anthonyv.net/fulldb.kml



Any help would be much appreciated.



Thanks in advance, and keep up the great work!



Ant.
Note: Comment imported. Original by Anthony V at 2007-06-26 17:25

Mark McLaren said...

Hi Anthony,



You are too kind, sad but true, I enjoy working with XML! If you want something really quick and dirty then nowadays Google can interpret KML files for you, e.g:







Identified Locations for the Integra Database





If you want something to embed in your website, I will need to do a little tweaking of my XSL stylesheet as KML has evolved a little since I wrote it back in July 2005.



Mark
Note: Comment imported. Original by Mark McLaren website: http://content.mark-mclaren.info/ at 2007-06-27 08:14

Mark McLaren said...

Hi Anthony,



I have slightly modified the work I did for Speakfree for your example. As with Speakfree's example I used the XSL only to generate some JavaScript arrays, the rest of the code I added by hand (you may need to tweak this further). Since your KML file contains two folders I have split your data across two pages (Integra Locations and Office Club Members).





anthonyV.xsl





anthonyV1.html

anthonyV2.html





HTH



Mark


Note: Comment imported. Original by Mark McLaren website: http://content.mark-mclaren.info/ at 2007-06-27 09:33

Mark McLaren said...

Thanks for the info Mark,



I'm aware that Google Earth is able to display the KML file - that's how i've been using it for the last few days since i completed the creation of the kml file.



Problem being is that i've tried using google maps to display the kml file (as in the link u provided), but not all of the points show up, which i'd assume is down to there being so many?



This is the problem i'm trying to get around... i need to be able to view my kml file (all placemarks) through google maps rather than google earth.



I've been looking about for some sourcecode/guides on creating my own google map to embed into a basic page, but can't seem to work out how to get a list of clickable placemarks beside my map when the map is displaying content from a KML file.



Any help would be much appreciated.



In summary, what i'm trying to achieve is a html page (either maps.google.com or a page of my own), which has a 600x500px map with my placemarks displayed, and a clickable list of points beside the map.



I had no joy pulling the kml file into maps.google.com (as mentioned), so my next approach was trying to change from using a kml file, to having the data in the correct format within the html page, to display the map in full.



Would very much appreciate any assistance with this, as i've spent ages looking around with no joy, and your blog i stumbled upon yesterday is the closest thing yet.



Thanks again,



Anthony.
Note: Comment imported. Original by Anthony V at 2007-06-27 09:34

Mark McLaren said...

Mark, that was great, thank you so much.

Is it not possible to have both of the folders or all points on one map tho? ...thats the key to what i'm trying to do.



Also, are you able to point me in the right direction for some info on how to make those points appear in a list beside the map so they're clickable?



Once again, your help is much appreciated and hope i'm not taking a mile for an inch in asking many questions.



Anthony.
Note: Comment imported. Original by Anthony V at 2007-06-27 14:34

Mark McLaren said...

Anthony, this is my first attempt at what you describe:



anthonyV1A.html

anthonyV2A.html





I think I could probably improve the efficiency of the JavaScript a bit more. Also listing the locations in alphabetical order should also be possible with a little bit more effort.





The key to this is once you have captured your data in a JavaScript array you are free to manipulate it as you see fit.




Note: Comment imported. Original by Mark McLaren website: http://content.mark-mclaren.info/ at 2007-06-27 14:56

Mark McLaren said...

I am tring to converte my KML file generated on google maps to use in the google maps api in joomla

Hope you can help

i tried conveted from kml to xsl but no successs.



following is the link of KML

http://maps.google.com/maps/ms?ie=UTF8&mpnum=3&msa=0&output=nl&msid=114539153869878703109.0004369f2c38a2d3201a7


Note: Comment imported. Original by Amit at 2007-08-01 11:07

Mark McLaren said...

Hi Amit,



I am afraid I know nothing about Joomla but I can produce a Google Maps page if that is helpful. The given link returns a KML file that contains a network link. At first loading the network link in the browser returned "{errorText:"Unable to contact server."}". After reading this forum entry I was able to acquire the source KML file.





I had to tweak one of the above XSL slightly to expect Placemarks directly inside Documents and then I was able to extract your data. I was then able to use the MyMaps icons following the technique described here.





Here is the result: Map of Thane





HTH



Mark
Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2007-08-01 20:37

Mark McLaren said...

Hello Mark,



I really do admire & appreciate your work and effort regarding this topic. Well, I am facing the same problem the others are facing. The resulting HTML output file is empty. May you please have a look at the KML File (http://208.109.237.99/members.kml)



Thanks,

Firas
Note: Comment imported. Original by FMourtada at 2008-02-18 11:16

Mark McLaren said...

Firas, the URL for your KML file is giving a "file not found" error.
Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2008-02-18 21:46

Mark McLaren said...

http://208.109.237.99/member.kml



Well, the KML file name is "member.kml" without an "s".
Note: Comment imported. Original by FMourtada at 2008-02-19 05:54

Mark McLaren said...

Oooh, Dubai, I have "celebrity" relations in Dubai! (if playing Golf makes you a celebrity!)



Anyway, I have tweaked an example from further up in the comments. I suspect you were getting blank outputs because the above example (from 2005) was written for KML 2.0 and we are now using KML 2.1 - so there was a namespace mismatch also, we can know much more about the format that we did back then (due to the availability of the XML schema).





Here is the XSL:

member.xsl





Here is the output (note I have added some of the JavaScript/HTML by hand):

member.html


Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2008-02-19 10:09

Mark McLaren said...

Well I'm not really into Golf though I would like to play it. Anyway, thanks a lot for your help.Cheers,Firas


Note: Comment imported. Original by FMourtada at 2008-02-20 08:18

Mark McLaren said...

Installed expat 2.0.1 and Sablotron 1.0.3. When I use the GPXtoHTML XSL transformation above of this GPX file: "http://conrose.com/scorpion.gpx"; I get this HTML output: "http://conrose.com/test.html".



My google keys work on other web pages from the same server. I also tried a simple change from the V1 to V2 version of the Google APIs by specifying v=2 and changing "new GMap" invocation to "new GMap2" - but still no luck. Any help/ideas appreciated ... I have been looking for something to script a GPX tracklog into a Google API call to display the map and track.
Note: Comment imported. Original by BrianC at 2009-02-05 03:37

Mark McLaren said...

I've tweaked the XSL and the transform works for me with your data. I'm sure you appreciate that this blog entry was written several years ago and the API has changed a little since then.





gpx2html.xsl





HTH



Mark
Note: Comment imported. Original by markmc website: http://content.mark-mclaren.info/ at 2009-02-05 08:55

Mark McLaren said...

Works like a charm now. I see the changes you made in the html output - not sure why they were required - but yes I kinda figured it was time or a Google API evolution issue. I've been casually looking for something like this for awhile - and this is the only thing I have came across. Now that this is working I have a starting point for trying some more incremental and ambitious changes. Your help is very much appreciated. I will try and pay it forward. Thanks.
Note: Comment imported. Original by BrianC at 2009-02-06 01:37

Mark McLaren said...

Do you have an updated file for kml to html?
Note: Comment imported. Original by casey at 2009-06-24 21:24

Mark McLaren said...

Mark,



I came across this blog while searching for a problem I'm having updating a kml. I am new to xml/xslt, and have tried using xselerator and msxsl but can't get past the undeclared variable. I am simply trying to perform an xslt to add to the kml.



Here is the before kml and the after kml I am trying to get to.



http://thunderbrain.net/gps/before.kml

http://thunderbrain.net/gps/after.kml
Note: Comment imported. Original by rbennu at 2010-02-09 18:52

Mark McLaren said...

Yes the data worked for me as well. API definitely evolves a lot since the post.
Note: Comment imported. Original by Wilshire Angeles website: http://www.movoto.com/real-estate/homes-for-sale/CA/Los-Angeles/10727-Wilshire-BLVD-204_10-444235.htm at 2010-05-06 22:14

Sinziana Armencea said...

If you want to convert KML files to GPX file or GPX to KML, you can use www.kml2gpx.com, it is free and it makes the conversion both ways.

Sinziana Armencea said...
This comment has been removed by the author.
Pengobatan Daging Tumbuh/kutil di kelamin said...

obat tradisional gatal kelamin wanita
cara mengobati kelamin wanita gatal
kelamin yg gatal
penyakit kelamin yang gatal
penyakit kelamin yg gatal
alat kelamin yang gatal
mengobati kelamin yang gatal
obat kelamin yg gatal
obat kelamin yang gatal
cara mengobati kelamin yang gatal
cara mengobati kelamin yg gatal
salep untuk kelamin yang gatal
kelamin keluar nanah dan darah
kelamin keluar nanah tapi tidak sakit
kelamin keluar nanah sedikit
obat kelamin keluar nanah
kelamin pria keluar nanah
penyebab kelamin keluar nanah
kelamin laki2 keluar nanah
akibat kelamin keluar nanah
kelamin anak keluar nanah
kelamin lelaki keluar nanah
kelamin keluar nanah
alat kelamin keluar nanah
obat kelamin keluar nanah di apotik
antibiotik kelamin keluar nanah
kelamin anjing keluar nanah
obat alat kelamin keluar nanah
penyebab alat kelamin keluar nanah
obat alami kelamin keluar nanah
kenapa alat kelamin keluar nanah
kelamin bayi keluar nanah
obat buat kelamin keluar nanah
kelamin cowok keluar nanah
cara mengobati kelamin keluar nanah
cara menyembuhkan kelamin keluar nanah
cara penyembuhan kelamin keluar nanah