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

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

问题描述

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

  var ctaLayer = new google.maps.KmlLayer( HTTP://本地主机:8080 / KML / cta.kml); 

这不起作用(没有任何东西会被加载)。

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

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

正确加载。两个kml文件是相同的。我自己提供服务时需要做些什么来加载它? (我尝试了绝对路径和相对路径,我知道我使用的路径是正确的......)

另外,我将正确的mime类型添加到我的应用服务器的配置文件:

 < 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>

但它仍然无法加载。



我在Google的文档中发现了这一点:


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


所以我想我要做的是不从可公开访问的URL中提供kml而不是 em> >解决方案

KML无法访问,因为它位于您的本地计算机上,并且Google无法访问它,因为它不知道如何进入localhost:8080


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");

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...)

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>

But it still doesn't load.

I found this in google's docs:

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.

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

解决方案

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

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

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