Android的 - 如何打开谷歌地图,意图和KML?意图、地图、Android、KML

2023-09-05 08:51:28 作者:·女人般的风骚

我需要打开使用KML文件至极SD卡上已经存在的谷歌地图。 (/sdcard/example.kml)

I need to open google maps using kml file wich already exists on sdcard. (/sdcard/example.kml)

我想:

Open当地的KML文件在谷歌地图上的Andr​​oid

这个答案是错的,当点击链接,地图开放,但搜索的位置文件:///sdcard/example.kml

this answer is wrong, when click on link, maps open, but search for location "file:///sdcard/example.kml"

使用意图:

这code抛出 ActivityNotFoundException

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
        Uri.parse("file:///sdcard/example.kml"));
startActivity(intent);

在我试图用setDataAndType方法,但心不是作品:

另一个 ActivityNotFoundException

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(
         Uri.parse("file:///sdcard/example.kml"),
                   "application/kml");
startActivity(intent);

有关此问题的另外两个尚未解决的主题:

打开本地的KML文件在谷歌地图上的Andr​​oid

是否在Android API支持KML文件?

不知道如何打开这个KML?

Any idea how to open this kml?

感谢您!

推荐答案

因为你的应用程序可能会或可能不会访问到SD卡(它可能或可能无法使用,例如),最可靠的解决方案是张贴KML文件到网络和充电回来(我假设你拥有网络访问权限,因为谷歌地图未启用将是多大用处下线的,甚至prefetching砖)。

since your app might or might not have access to the sdcard (it might or might not be available, for instance), the surest solution is to post KML file to the web and charge it back (i assume that you have web access because google maps isnt going to be of much use offline, even prefetching tiles).

即使你有支付违约金(Google地图是在分析和嵌入KML功能慢),这是值得的,海事组织。

even if you have to pay a penalty (googlemaps is slow in parsing and embedding kml features), it is worth it, IMO.

例如,如果你使用一个样本KML文件(如下面的):

for example, if you use a sample kml file (like the one below):

String kmlWebAddress = "http://www.afischer-online.de/sos/AFTrack/tracks/e1/01.24.Soltau2Wietzendorf.kml";
String uri = String.format(Locale.ENGLISH, "geo:0,0?q=%s",kmlWebAddress);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(intent);

测试工作。刚刚发布您的KML文件到文件服务器和访问的方式。

tested and working. just post your kml file to a fileserver and access it that way.

请注意:如果你打算更新您​​的地图上实时,Google地图倾向于避免通过缓存文件的时间(待定)一段时间。如果您使用的是随机数发生器在您的KML字符串的结尾像?随机函数发生器= [RandomNumber] 你也许能逃脱实时更新。

NOTE: if you plan on updating your map in realtime, googlemaps tends to avoid that by caching files for a certain period of time (undetermined). if you use a randomizer at the end of your kml string, like ?randomizer=[RandomNumber] you might be able to get away with realtime updating.