我正在尝试编写,然后通过Intent使用Google地图加载KML文件。我已经尝试了KML文件的内部和外部存储 - 它似乎写得正确,但我一直在Google地图中收到以下错误Toast:
找不到以下结果:file:/// data / data / [我的应用包路径] /kml_to_view.kml
File dir = context.getFilesDir();
//File dir = Environment.getExternalStorageDirectory();
Log.d(TAG, "Writing to dir: " + dir);
File kmlFile = new File(dir, KML_FILE_NAME);
FileOutputStream fos;
try
{
kmlFile.createNewFile();
fos = context.openFileOutput(KML_FILE_NAME, Context.MODE_WORLD_READABLE);
//fos = new FileOutputStream(kmlFile);
fos.write(kmlData.getBytes());
fos.close();
isKMLPrepared = true;
Toast.makeText(context, "file write successful", Toast.LENGTH_LONG);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG);
e.printStackTrace();
}
正如您所看到的,我有必要写入内部存储或外部存储,我已经尝试过。
File dir = context.getFilesDir();
Log.d(TAG, "Local file path: " + dir);
readInternalStoragePrivate(KML_FILE_NAME);
mapsIntent = new Intent(Intent.ACTION_VIEW);//Uri.parse("http://maps.google.com/maps"));
//String uri = "geo:0,0?q=file://" + Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + KML_FILE_NAME;
String uri = "geo:0,0?q=file://" + context.getFilesDir().getAbsolutePath() + "/" + KML_FILE_NAME;
Log.d(TAG, "URI: " + uri);
mapsIntent.setData(Uri.parse(uri));
在向地图应用发送路径时,我再次尝试阅读内部和外部位置。
知道我需要做些什么来让地图应用程序读取和处理本地存储的KML文件?我已经阅读了其他一些帖子,但我还没有找到解决问题的方法。