Friday, December 19, 2008

Android, Google Earth and KML routes

Whilst testing location based applications, the need to simulate routes is likely to appear.
This article shows you how to obtain KML routes using Google Earth, convert it to a suitable format to be loaded into Eclipse ADT plugin Emulator Control and be able to test location based applications.

Create the route
Using Google Earth, create the route using Directions.

Then right click on Route, at the end of the list of directions, and save it. Let's say, we save it as myroute.kmz.

Convert the route
To be used with the current version of Android ADT plugin (0.8.0) a slightly different format is needed as is not supported.
We have to convert the route to use multiple s.

The change is really simple and we could do it manually, but fortunately there's an application to automate this task.
ge2adt is hosted on Google Appengine and can be reached at http://ge2adt.appspot.com/.
Use your Google identifier to access it (i.e.: you gmail account).

Unzip kmz, extract doc.kml, rename it, upload myroute.kml, convert it, and save the result as myroute-adt.kml.

Test my location
Using Eclipse Android DDMS perspective, under Emulator Control, load the converted KML file myroute-adt.kml.


Once the route is loaded, use you location based application or launch Maps, select My Location on the menu, press the play button on Emulator Control and you will be able to appreciate the map moving along the route.



11 comments:

Unknown said...

Great info, but I cannot get the converted kml file working for the ADT plugin version 0.9.4 Any tips?

Unknown said...

Hmm I found out that the generated files are actually buggy and incomplete, there seems to be an issue with ge2adt itself.

Diego Torres Milano said...

Probably there are some bugs. Feel free to report them as well as any other suggestion.

Diego Torres Milano said...

I've tested ge2adt and Android ADT 0.9.4v2 and DDMS rev3 and Android 1.5 Google API 3 and everything worked fine.
The route tested can be downloaded from android tools.
If you find a bug, please report.

Unknown said...

I am not sure where to file a bug, except for here?

Here is how to reproduce the issues I am seeing. Create a route from Longmont, CO to St. Paul Minnesota. Convert it with the web application. If you open the file you will find there are multiple embeded kml documents in the converted file. Deleting the extra kml documents will allow Google Earth and Android's plugin to open the route, but it will only be a partial route.

Diego Torres Milano said...

Thanks for reporting.
Unfortunately the bug is not in ge2adt (AFAIK). I've tested the same route (Longmont,CO to St. Paul, MN), converted it and the resulting file seems OK.
The problem seems to be in DDMS not being able to load such a long file. You can trim the file and see that loads with no problem.

Unknown said...

That is odd because I cannot even load the resulting file into Google Earth. AFAIK Google Earth should support the separate KML version files just fine. There are two instance documents in the resulting file when I do the generation in ge2adt. The line and column number of the error Google Earth gives me coincides with the start of the second xml instance document within the file.

If I remove the second instance document it will load up into Google Earth and DDMS Perhaps it has to do with the version of Google Earth I'm using. It appears that ge2adt at some point decides to end the full XML data structure and creates a new complete xml document in the generated file instead of continuing to append the points to the route in the original instance document.

I am using the newest version of Google Earth (5.1.3509.4636) perhaps the routes being generated from this version of Google Earth is causing issues with ge2adt?

Unknown said...

I fixed it (at least it works for me)
The kml file generated by ge2adt for 2 coordinates is like:




GE2ADT
0GE2ADT Route-5.84458,43.35922,0




GE2ADT
0GE2ADT Route-5.84482,43.35911,0



Which makes the ADT not load it.
Instead of that, try:




GE2ADT
0GE2ADT Route-5.84458,43.35922,0
0GE2ADT Route-5.84482,43.35911,0



That is: only 1 kml tag, with several placemark tags.
Hope it helps

Unknown said...

Too bad it doesn´t show ok.
You can contact me at carlos.rayon.mn@gmail.com, i´ll send you the xml if you want.

Josep Gil said...

Very usefull.
Thanks
José

Diego Torres Milano said...

Thanks for your comment.
I'm glad to hear you found it useful.