托管自定义 KML 以供 Google 手机地图使用的秘诀是什么?

发布于 2024-09-10 02:10:25 字数 1368 浏览 3 评论 0原文

我是 Android 新手,所以我可能会错过一些非常基本的东西。

我正在尝试在防火墙后面的服务器上托管自定义 KML 文件,并在 Android 模拟器上显示这些 KML 文件。

我首先编写一个简单的应用程序,使用 Intent 显示叠加层并将应用程序指向 geo:0,0?q=http://code.google.com/apis/kml/documentation/KML_Samples.kml。这在模拟器中有效。

接下来,我下载了该 KML 文件并将其发布到我的 Web 服务器(Fedora 上的 Apache 2.2)上。我为 .kml 扩展名添加了 AddType 指令并重新启动了 HTTPD。

当我将简单应用程序的 Intent 指向内部托管的 KML 文件时,我收到错误“无法显示社区地图,因为它包含错误。”

我添加了一些代码来尝试独立于 KML 下载 KML 文件,以便我可以检查状态行等:

final HttpClient client = new DefaultHttpClient();
final HttpGet get = new HttpGet("http://mycompany.com/data/KML_Samples.kml");
try {
    final HttpResponse resp = client.execute(get);
    android.util.Log.e("MapOverlays", resp.toString());
} catch (Throwable t) {
    android.util.Log.e("MapOverlays", "Exception", t);
}

通过第一个日志消息行上的断点,我可以检查结果:

statusline =“HTTP/1.1 200 OK”

内容类型:application/vnd.google-earth.kml+xml

这是我正在使用的意图:

final Intent intent = new Intent(
android.content.Intent.ACTION_VIEW,
        Uri.parse("geo:0,0?q=http://mycompany.com/data/KML_Samples.kml"));
startActivity(intent);

所以两个主要问题是

  1. 我需要做什么才能从私人服务器加载 KML?
  2. 有哪些工具(如果有)可以用来确定我所做的事情有什么问题(比“社区地图...”提供更多信息)?

谢谢

I am new to Android and so I may be missing some very basic things here.

I am trying to host custom KML files on a server behind my firewall and display those KML files on the Android emulator.

I started by writing a simple app that uses an Intent to display the overlay and pointing the app at geo:0,0?q=http://code.google.com/apis/kml/documentation/KML_Samples.kml. This works in the emulator.

Next I downloaded that KML file and posted it on my web server (Apache 2.2 on Fedora). I added an AddType directive for the .kml extension and restarted HTTPD.

When I point my simple app's Intent to my internally hosted KML file I get the error "The community map could not be displayed because it contains errors."

I added some code to try and download the KML file independently of the KML so I could check the status line and the like:

final HttpClient client = new DefaultHttpClient();
final HttpGet get = new HttpGet("http://mycompany.com/data/KML_Samples.kml");
try {
    final HttpResponse resp = client.execute(get);
    android.util.Log.e("MapOverlays", resp.toString());
} catch (Throwable t) {
    android.util.Log.e("MapOverlays", "Exception", t);
}

With a breakpoint on the first Log message line I can inspect the results:

statusline = "HTTP/1.1 200 OK"

Content-Type: application/vnd.google-earth.kml+xml

Here's the Intent I'm using:

final Intent intent = new Intent(
android.content.Intent.ACTION_VIEW,
        Uri.parse("geo:0,0?q=http://mycompany.com/data/KML_Samples.kml"));
startActivity(intent);

So the two main questions are

  1. What do I need to do to get KML loaded from a private server?
  2. What tools are available (if any) to determine what is wrong with what I've done (something more informative than "The community map...")?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗喜 2024-09-17 02:10:25

这些可能是愚蠢的问题,但我需要知道您是否已验证相关 KML 文件实际上是有效的 KML。

您可能遇到的另一个问题是您正在下载的 KML 文件包含网络链接,这些链接本身无法从您的 Android 设备访问。

These may be silly questions, but I need to know whether you have verified that the KML file in question is in fact valid KML.

Another problem that you may have is that the KML file you are downloading contains network links which are themselves not reachable from your Android device.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文