Jump to content

How to display KML files on MyTopo maps with new Google map viewer


Recommended Posts

Hello Everyone,

 

My name is Joseph Elfelt and I have a Thanksgiving Day present for you.

 

Many of you know that the standard map viewer supplied by Google can read and display data from a kml file. Here is an example using the map viewer supplied by Google and showing my GPS track for a hike I have done a couple of times in the Washington State Cascades:

http://maps.google.com/?q=http://www.mappi...pic.kml&t=p

While the ‘Terrain’ view in the standard Google map viewer is nice, it is not the same as seeing the data in your kml file displayed on a 7.5” USGS topographic map.

 

Here is the very same kml file displayed using an alternative map viewer that I recently finished coding:

http://www.mappingsupport.com/p/gmap4.php?...il_with_pic.kml

 

Did you notice the embedded picture link?

 

The gmap4 map viewer is free, full screen, no ads. It can read and display any kml file hosted anywhere online. The topo maps are the same MyTopo maps that are used on this site. I think they cover Canada as well as the USA.

 

Here are some of the ways you can obtain a kml file containing your GPS and related data:

1. GPSBabel They re-designed their website since I saw it last.

2. GPSVisualizer. The output includes a fair bit of clutter in the form of tags that are used by Google Earth but are ignored by Google maps.

3. By hand. Here is the documentation from Google and there are examples in the tutorial. You must save a kml file with UTF-8 encoding. I use the free Notepad++ for editing kml files. Since kml files are a type of xml file, it really helps a lot to use an editor designed for working with xml files.

 

See the kml source file I used in the above example map for one approach for organizing the contents of a kml file.

 

Oh, and anything you include in the <Document><description> tag is treated as a caption and gets welded to the top of the map. See my example source files.

 

The gmap4 map viewer understands these parameters:

q= http: pointer to a kml file online

ll= map center. For North America use lat,-lon decimal degrees (same as Google, etc)

z= map zoom

t= map type

 

To launch gmap4:

(not a link) http://www.mappingsupport.com/p/gmap4.php?...ing_to_kml_file

or

(not a link) http://www.mappingsupport.com/p/gmap4.php?ll=lat,-lon

or

http://www.mappingsupport.com/p/gmap4.php to see the default map (Google’s campus at Kirkland, WA)

 

To fully specify a map, use all 4 parameters.

http://www.mappingsupport.com/p/gmap4.php?...p;z=14&t=t2

 

But what if you don’t have your own website for hosting your kml file online? No worries. You can store your kml file in the cloud as a Google Document txt file and read it with the gmap4 map viewer. Since I’ve already given you a bunch to think about in this post, I’ll save those details for later.

 

Teaser: If several people are working together to make a trail map for an area, everyone in that group can pool their data by directly editing the same file in the Google cloud.

 

Enjoy and Happy Thanksgiving,

Joseph Elfelt

Link to comment

I just remembered something that may help people that have a GPS unit that produces GPX files. You can use Google Earth to convert a GPX file to a KML file. You can then view your GPS data on 7.5” topo maps (full screen, no ads, free) by using the gmap4 map viewer.

 

Here’s how to use Google Earth to convert a GPX file to a KML file :

 

1. Open your GPX file with Google Earth. Your file can be on your local drive.

2. File ==> Save ==> Save Place as ==> Set ‘Save as type’ to KML ==> save the file

 

All you need to do now is place your KML file online and point to it with the gmap4 map viewer. See my earlier post for details.

 

Joseph

Link to comment

This is a great thanksgiving treat. I have been looking for some methods on how to do this for awhile. Let us know if you have a blog that you regularly post your findings. I want to have my own kml file with links to my pictures and embed that in my web pages.

 

questions

How did you create the KML? did you write it by hand, or use a program to convert from something else. I know of an Excel to KML converter. any suggestions? Im a programmer and not afraid of writrng raw kml, but would rather not if I dont have to.

 

any links, books or examples you look at for inspiration? thanks for the great info.

Link to comment

Thanks for the kind words.

 

Here is the kml documentation from Google: http://code.google.com/apis/kml/documentation/

There is a tutorial, etc. Great resource for ideas/inspiration.

 

If you edit kml by hand then you must save the file with utf-8 encoding.

 

I started creating kml files by using the free site GPSVisualizer and uploaded my gps track. That site creates a kml file that you can download to your local drive. Now I do them by hand so they are (1) more organized and (2) do not have a bunch of tags that are ignored by Google maps.

 

Here is one of the kml files I am using for the demo maps:

http://www.mappingsupport.com/p/kml_demo/c...il_with_pic.kml

Anyone is welcome to download that file and use it as a template. It has 2 tracks with different colors and one photo link.

 

You will not be able to embed the actual map produced by gmap4 in your web page. Instead you can include a link on your page that will launch gmap4 and display your kml file. The url to use for the link is:

(not a real link)

http://www.mappingsupport.com/p/gmap4.php?q=http://...

Point the q parameter to wherever your kml file is hosted online.

 

If you want to embed an actual map on your site then you will have to use the Google maps API and roll your own. Grab my source code for gmap4 to see how to include the MyTopo 7.5 topographic maps if you decide to go this route.

 

Among other things I need to revise my website (www.MappingSupport.com) to add content about gmap4 and write a 'help' file.

 

If you have a gpx file you can easily convert it to kml. See my earlier posts in this thread. My next enhancement will allow gmap4 to directly read gpx files. Stay tuned...

Link to comment

Correction to gmap4 map viewer

 

In an earlier post I indicated that any text in the <Document><description> element of your kml file would become a caption that gets welded to the top of your map. Oops! It was a mistake on my part to initially identify that element as the one where gmap4 would pick up text for a map caption. Instead, please use the <Document><name> element if you would like a caption on your map.

 

For example, this is how I coded a three line, bolded caption for the following demo map:

<Document>

<name><![CDATA[<b>Includes part of County Line<br>trail (faint). GPS tracks<br>from 2004 and 2008.</b>]]></name>

 

http://www.mappingsupport.com/p/gmap4.php?...779657&z=14

 

Gmap4 will now ignore anything in the <Document><description> element of kml files.

 

To read more about adding html to your kml files, and the CDATA tag, please open this link and scroll down a bit:

http://code.google.com/apis/kml/documentation/kml_tut.html

 

If you use map captions, then I recommend keeping your caption and <name> tags on a single line in your kml file, like so:

<name><![CDATA[Your caption here. HTML is OK]]></name>

 

My apologies for any inconvenience this change will cause anyone.

 

Making changes to your map - &refresh=1

 

The MASU (MAppingSUpport) server must keep a copy of your kml file in order to display your data via Google maps. If you change the content of your kml file but do not change your file name, then you need to tell gmap4 that it should re-read your file and make a new copy. You can do this by first placing your revised file online and then launching gmap4 with this additional parameter: &refresh=1

For example: http://www.mappingsupport.com/p/gmap4.php?...4&refresh=1

 

After you revise your kml file, you only need to use the refresh parameter one time. Since the refresh parameter causes additional processing, it should not be routinely used. It only needs to be used 1 time after a kml file has been changed.

 

Google cache

 

Google maintains its own cache for kml files. This is different than your browser’s cache. If you make a change to your kml file then you will not see that change in gmap4 until Google decides to refresh its cache of kml files. Sorry about that but it’s out of my hands.

 

Testing kml files with Google Earth

 

Google Earth can read and display kml files from your local drive. If you change your file you can tell Google Earth to refresh itself with the revised data. This is a great tool to help you develop a kml file. The problem I described in the prior paragraph regarding the Google cache does not apply if you develop your kml files with Google Earth.

 

Store your kml files in the Google cloud

 

This feature is unique to gmap4.

 

In order for gmap4 to read your kml file, you must place that file online somewhere. And for those that do not have their own website - no worries - you can upload your data to the cloud as a Google document and let Google host your kml/txt file for free. However, since Google documents does not provide native support for kml files, you need to pay attention and follow these instructions:

 

1. Get a Google account. It’s free.

2. Change the extension on your file from kml to txt. Kml files are a type of text file.

3. Connect to Google documents and login. http://docs.google.com/

4. Spend a little time learning your way around

5. Upload your kml/txt file

6. “Share” your file for viewing by anyone

7. “Publish” your file (check one file box ==> More actions ==> Check the box to “Automatically re-publish” ==> Publish)

8. Copy and save the url you get when you “publish”.

9. Launch gmap4 to view the data in your “published” file:

http://www.mappingsupport.com/p/gmap4.php?...e,_____________

Replace the underscore with the id for your “published” file:

 

Here is a link to a different version of the demo map you have already seen. This specific file is stored as a Google document. Note that it does not have any caption at the top of the map. That is because this file does not have any text in the <Document><name> element of the kml file.

http://www.mappingsupport.com/p/gmap4.php?...b4rd_18dv5zkmdb

 

Tech note: Google adds a lot of html code to each file that is uploaded into Google documents. After reading one of these kml/txt files, gmap4 unwraps the html and converts the file back into a normal kml file which can then be read by Google maps. This feature is unique to gmap4.

 

Status of enhancement to support gpx files

 

The coding is finished and testing is underway. Here’s some insight into how this will work. Google maps understands kml files but does not understand gpx files. After I release this enhancement you will be able to launch gmap4 with the q parameter pointing to a gpx file hosted anywhere online. Gmap4 will read that file and use GPSBabel to convert it to a kml file. That conversion step will use the default settings built into GPSBabel. If those default conversion settings do not give you what you want to see on your gmap4 map, then you will need to run GPSBabel yourself and adjust the conversion settings to produce a kml file more to your liking. You can then place that kml file online somewhere and then display that data with the gmap4 map viewer.

 

Future enhancements

 

Actually before working on any more enhancements I really need to write v.1 of a ‘help’ file.

 

High on the list of future enhancements is the ability to click the map and build a list of coordinates. You will be able to copy those coords and save them on your local drive. Of course once the coords are on your drive you can process them with GPSBabel (or various other tools) and convert them into a gpx file or any other kind of file supported by your conversion tool. In this manner you will be able to load coords into your GPS prior to your next trip.

 

Bug reports

 

Please let me know if anything seems awry. I will try to check back here periodically but if I seem AWOL you can always email me through my website: www.MappingSupport.com

Since gmap4 is under active development, it is certainly possible that in adding a new feature I will accidentally break something that previously worked fine.

 

Enjoy,

Joseph Elfelt

Link to comment

Here’s some cheery news. The gmap4 map viewer can now read GPX files. You should see version 1.2.023 in the lower left corner of the map. If not, please clear your browser’s cache and try again.

 

Be sure to read my prior post explaining that ‘under the hood’ gmap4 uses the default settings of GPSBabel to convert your GPX file into a KML file. That step is essential since Google maps does not understand GPX files.

 

If you do not like how your data looks on the map with this default conversion, then it is a simple matter for you to run GPSBabel on your own computer and tweak its options. By doing so you can produce a kml file that you can feed to gmap4 and see your data the way you want it to look.

 

Please do not store GPX files as a Google document. That feature only works for KML files. Some time in the future I will investigate turning this feature on for GPX files.

 

Please let me know if something does not work right.

 

Enjoy :)

Joseph

Link to comment

Do you have any .TPO files from the National Geographic TOPO software? Gmap4 version 1.7.x can now display those files. Often the topographic maps displayed by Gmap4 (provided at no cost by www.MyTopo.com) will be superior and/or more current than the NG topographic maps displayed by the TOPO software.

 

You do need to place your TPO or other data file online before it can be displayed by Gmap4. The easiest/fastest way to place a TPO file online is via Google Sites (free). Don’t be shy. You will find hand-holding-step-by-step instructions in the Gmap4 Help file.

 

Here is the general recipe for building a URL to display a TPO file with Gmap4 (do not include the quotes, this is not a real link):

'http://www.mappingsupport.com/p/gmap4.php?t=t2&q=htpp://url_to_your_file.tpo'

 

Below is a link to the Gmap4 homepage. Check out the 'Examples' button and Quick Start section of the 'Help' file.

http://www.mappingsupport.com/p/gmap4.html

 

Enjoy,

Joseph

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...