我不知道你是否看过惊人的Mytrack更新,但它允许将一个kml文件发送到Google Earth应用程序并将其显示在Google应用程序中(当然,如果已安装).
源代码在那里:http://code.google.com/p/mytracks/source/browse/
但我无法找到实现这一目标的方法.
else if (playTrack) { Intent intent = new Intent() .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) .putExtra(GOOGLE_EARTH_TOUR_FEATURE_ID,KmlTrackWriter.TOUR_FEATURE_ID) .setClassName(GOOGLE_EARTH_PACKAGE,GOOGLE_EARTH_CLASS) .setDataAndType(Uri.fromFile(new File(savedPath)),GOOGLE_EARTH_KML_MIME_TYPE); startActivity(intent);
硬编码方式提供此代码:
Intent intent = new Intent() .addFlags( Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK) .putExtra("com.google.earth.EXTRA.tour_feature_id","tour") .setClassName("com.google.earth","com.google.earth.EarthActivity") .setDataAndType(Uri.fromFile(new File("/sdcard/test.kml")),"application/vnd.google-earth.kml+xml"); startActivity(intent);
Intent mapIntent = new Intent(Intent.ACTION_VIEW); Uri uri1 = Uri.parse("file:///sdcard/test.kml"); mapIntent.setData(uri1); startActivity(Intent.createChooser(mapIntent,"Sample"));
我的目标是通过“播放”按钮获得相同的结果.
解决方法
您需要指定KML文件的URI和KML MIME类型,如下所示.
File file = new File(Environment.getExternalStorageDirectory(),"sample_tour.kml"); 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","my_track"); startActivity(intent);
这目前没有记录,但我们正在寻求解决这个问题.
一定要分别使用Intent :: setDataAndType而不是Intent :: setData和Intent :: setType(它们各自覆盖另一个).
“my_track”是对地标ID的引用.意图额外自动开始游览.
<Placemark id="my_track"> <gx:Track> ... </gx:Track> </Placemark>