【发布时间】:2013-11-06 07:30:03
【问题描述】:
我正在开发基于位置的应用程序。我想将给定的地图导出到 kml 文件并将 kml 文件导入到 android google map。有没有办法在 android 中实现 kml?
【问题讨论】:
标签: android google-maps kml
我正在开发基于位置的应用程序。我想将给定的地图导出到 kml 文件并将 kml 文件导入到 android google map。有没有办法在 android 中实现 kml?
【问题讨论】:
标签: android google-maps kml
对于 KML 实施,您可以研究一下 - How to draw a path on a map using kml file?
KML 文件的基本结构
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Placemark>
<name>My Simple Placemark</name>
<description>Your Description goes here</description>
<Point>
<coordinates> longitude, latitude, and optional altitude</coordinates>
</Point>
</Placemark>
</kml>
Kml 教程visit here 和KML 路径visit here
在安卓手机上加载KML文件需要包含以下代码:
final Intent myIntent =
new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://myurl.com/kmlcode/path/KML_Sa
mples.kml"));
startActivity(myIntent);
或
final Intent myIntent =
new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("file:///myurl.com/kmlcode/path/KML_Sa
mples.kml"));
startActivity(myIntent);
上面的代码将打开谷歌地图应用程序,它会从指定的 URL 或文件请求 kml 文件。
要在 android 手机上实现 google API,您必须添加 Google API 库并将构建目标设置为 Google API。您还需要在 AndroidManifest.xml 文件如下:
<manifest
xmlns:android="http://schemas.android.com/apk/res/
android"
package="com.example.package.name">
...
<application android:name="MyApplication" >
<uses-library
android:name="com.google.android.maps" />
...
</application>
...
<uses-permission
android:name="android.permission.INTERNET" />
</manifest>
要添加 MapView 控件,您需要在布局文件中编写以下代码:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:apiKey="Your Maps API Key goes here"
/>
希望这会对您有所帮助。
【讨论】:
抱歉,目前没有从给定安卓地图导出 KML 的方法。一旦您在 Android Google Map API V2 上显示 kml,就无法恢复它。
导出 您必须设计一种方法,在更新地图时更新您的 kml,或者在更新地图时更新一个跟踪所有 kml 标记和 kml 点等的类,以便您以后可以序列化 kml。
进口 那里有一些示例,但您几乎必须滚动自己的 kml 显示。在github上找东西,也许有人大方。
【讨论】: