【问题标题】:Android Google Maps/Earth opening Local KML/KMZ file and play the tour functionalityAndroid Google Maps/Earth 打开本地 KML/KMZ 文件并播放游览功能
【发布时间】:2014-11-21 09:36:19
【问题描述】:

有没有办法在 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 Drive 文件的链接以直接显示在 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"));

最后,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);

【问题讨论】:

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


    【解决方案1】:

    据我所知,在地图中这是不可能的,因为 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:网络故障”。我使用的是 Google 地球版本 8.0.1.2311
    • 我也知道了,搜了一圈,好像是earth 8的问题,有人建议降级到ver. 7
    【解决方案2】:

    我尝试了这种代码的和平,它工作得很好,除了你必须更改对你的 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);
    

    【讨论】:

      【解决方案3】:

      这对我有用:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-09
        相关资源
        最近更新 更多