使用谷歌地图加载本地 .kml 文件? [英] Loading a local .kml file using google maps?

查看:79
本文介绍了使用谷歌地图加载本地 .kml 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个 hello world 程序来加载本地 kml 文件(从 google 的文档中借用):

I created a hello world program to load a local kml file (borrowed from google's docs):

var ctaLayer = new google.maps.KmlLayer("http://localhost:8080/kml/cta.kml");

这不起作用(没有加载任何内容).

This does not work (nothing gets loaded).

但是,当我将该行更改为:

However, when I change that line to:

  var ctaLayer = new google.maps.KmlLayer("http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/cta.kml");

它正确加载.两个 kml 文件是相同的.我自己上菜时需要怎么做才能加载它?(我尝试了绝对路径和相对路径,我知道我使用的路径是正确的...)

it loads properly. Both kml files are identical. What do I need to do to get it to load when serving it myself? (I tried both absolute and relative paths, and I know the paths I am using are correct...)

我还在应用服务器的配置文件中添加了正确的 MIME 类型:

Also I added the correct mime type to my appserver's config file:

<mime-mapping>
    <extension>kml</extension>
<mime-type>application/vnd.google-earth.kml+xml</mime-type>
</mime-mapping>
<mime-mapping>
    <extension>kmz</extension>
    <mime-type>application/vnd.google-earth.kmz</mime-type>
</mime-mapping>

但它仍然无法加载.

我在谷歌的文档中找到了这个:

I found this in google's docs:

Google Maps API 支持用于显示地理信息的 KML 和 GeoRSS 数据格式.这些数据格式使用 KmlLayer 对象显示在地图上,该对象的构造函数采用可公开访问的 KML 或 GeoRSS 文件的 URL.

The Google Maps API supports the KML and GeoRSS data formats for displaying geographic information. These data formats are displayed on a map using a KmlLayer object, whose constructor takes the URL of a publicly accessible KML or GeoRSS file.

所以我想我正在尝试做的是不可能如果不从可公开访问的 url 提供 kml...除非有人可以证明否则

So I guess what I am trying to do is not possible without serving the kml from a publicly accessible url...unless someone can prove otherwise

推荐答案

无法访问 KML,因为它在您的本地计算机上,而 google 无法访问它,因为它不知道如何访问 localhost:8080

The KML can't be accessed since it's on your local machine and google can't access that since it doesn't know how to get to localhost:8080

这篇关于使用谷歌地图加载本地 .kml 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆