Android Google Maps/Earth opening Local KML/KMZ file and play the tour functionality

3.1k views Asked by At

Is there a way to open a local KML/KMZ file in Google Maps/Earth app on Android? Tried the below approach but didn't work.

    Intent mapIntent = new Intent(Intent.ACTION_VIEW);
    Uri uri1 = Uri
            .parse("geo:0,0?q=file:///mnt/sdcard/doc.kml");
    mapIntent.setData(uri1);
    startActivity(Intent.createChooser(mapIntent, "Sample"));

If not and if we can specify only links that are hosted on the web then can we specify a link to the Google Drive file to show directly on Google Maps/Earth?

    Intent mapIntent = new Intent(Intent.ACTION_VIEW);
    Uri uri1 = Uri
            .parse("geo:0,0?q=https://drive.google.com/open?id=0B8n3LAJCTg-8eml4TTBoZDlRd00&authuser=0");
    mapIntent.setData(uri1);
    startActivity(Intent.createChooser(mapIntent, "Sample"));

And finally what happened to the play tour functionality in Google Earth? It used to work but with the latest updates its broken and no longer working.

    File file = new File(playFileNameKml);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file),
            "application/vnd.google-earth.kml+xml");
    intent.putExtra("com.google.earth.EXTRA.tour_feature_id", "tour");
    startActivity(intent);
3

There are 3 answers

2
Arnold On

As I know, in Maps its impossible since the URI must be online address that google servers can access. Regarding Earth, that was working for me:

     path = Environment.getExternalStorageDirectory() + "/file.kml";
     packageName = "com.google.earth";
     Intent earthIntent = new Intent(android.content.Intent.ACTION_VIEW);
     earthIntent.setDataAndType(Uri.parse("file:/"+ path), "application/vnd.google-earth.kml+xml");
     earthIntent.setClassName(packageName, "com.google.earth.EarthActivity");
     targetedShareIntents.add(earthIntent);
0
noloman On

This is what has just worked for me:

Uri uriFromFile = FileProvider.getUriForFile(Install_sinapseActivity.this, GenericFileProvider.class.getName(), file); try { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uriFromFile, "application/vnd.google-earth.kml+xml"); intent.putExtra("com.google.earth.EXTRA.tour_feature_id", "my_track"); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivity(intent); catch (ActivityNotFoundException e) { ... }

0
volonte volonte On

I try this peace of code and it works great, except that you have to change permission to your kml file

File file = new File(playFileNameKml);

file.setReadable(true, false); // for reading you can add for writing  //and/or ecuting if you need that
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(file),
        "application/vnd.google-earth.kml+xml");
intent.putExtra("com.google.earth.EXTRA.tour_feature_id", "tour");
startActivity(intent);