I need to open google maps using kml file wich already exists on sdcard. (/sdcard/example.kml)
I tried:
this answer is wrong, when click on link, maps open, but search for location "file:///sdcard/example.kml"
This code throws ActivityNotFoundException
:
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("file:///sdcard/example.kml"));
startActivity(intent);
- I tried use setDataAndType method, but isnt works:
Another ActivityNotFoundException
:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(
Uri.parse("file:///sdcard/example.kml"),
"application/kml");
startActivity(intent);
- Other two unsolved topics about this issue:
Open local KML File in Google Maps on Android
Does the Android API support KML files?
Any idea how to open this kml?
Thank you!!!
I´m using Locus Free (from the market), which is a map visor that has the capability to open .kml files like those captured from google maps, BUT as well as is capable to import the .kml file from google, it does not let you see the satelite view, only the markers that you have added to it and some terrain features like roads and geographical names.
since your app might or might not have access to the sdcard (it might or might not be available, for instance), the surest solution is to post KML file to the web and charge it back (i assume that you have web access because google maps isnt going to be of much use offline, even prefetching tiles).
even if you have to pay a penalty (googlemaps is slow in parsing and embedding kml features), it is worth it, IMO.
for example, if you use a sample kml file (like the one below):
String kmlWebAddress = "http://www.afischer-online.de/sos/AFTrack/tracks/e1/01.24.Soltau2Wietzendorf.kml";
String uri = String.format(Locale.ENGLISH, "geo:0,0?q=%s",kmlWebAddress);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);
tested and working. just post your kml file to a fileserver and access it that way.
NOTE: if you plan on updating your map in realtime, googlemaps tends to avoid that by caching files for a certain period of time (undetermined). if you use a randomizer at the end of your kml string, like ?randomizer=[RandomNumber]
you might be able to get away with realtime updating.
You need to use the geo URI scheme syntax for your Intent data:
Uri.parse("geo:0,0?q=file:///sdcard/example.kml")
The code in this answer works for me:
How to plot a pre-build map from google maps on a MapView
I'm not surprised that the above does not work for me (on Android v2.1) because I think that all Maps does is send the query string off to the server to deal with. The server can deal with http:// because (with usual internet caveats!) the file can be fetched from anywhere. But it cannot deal with file:// because that only means something at the originating device, which the server cannot do anything about. I do not believe that Google Maps can process a local KML file, at least that way. Google Maps on Windows Mobile 5.0 can do so, however, if it is given the local file name in the traditional DOS command line manner. Surely this must be in Android too, in an Intent-ional manner!