Android Google Maps / Earth打开本地KML / KMZ文件并播放游览功能

时间:2014-11-21 09:36:19

标签: android google-maps kml google-earth kmz

有没有办法在Android上的Google Maps / Earth应用中打开本地KML / KMZ文件?尝试了以下方法,但没有成功。

    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"));

如果没有,如果我们只能指定在网络上托管的链接,那么我们是否可以指定一个指向Google云端硬盘文件的链接,以直接在Google地图/地球上显示?

    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"));

最后Google地球游戏功能发生了什么变化?它曾经工作,但最新的更新已破坏,不再有效。

    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 个答案:

答案 0 :(得分:0)

据我所知,在地图中它是不可能的,因为URI必须是谷歌服务器可以访问的在线地址。 关于地球,这对我有用:

     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);

答案 1 :(得分:0)

我尝试这种代码安静,它很有效,除了你必须更改你的kml文件的权限

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);

答案 2 :(得分:0)

这就是对我有用的东西:

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) { ... }