Google Maps KML Layer无法读取kml [英] Google Maps KML Layer won't read kml

查看:117
本文介绍了Google Maps KML Layer无法读取kml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Google Maps API 3阅读一个简单的KML,我在Google Maps Editor中创建了KML文件,代码是google示例,我找不到问题所在.

I'm trying to read a simple KML with Google Maps API 3, I created KML file in Google Maps Editor, codes are google sample, i can't find where is problem.

gm-sample.html

BTM.kml

function initMap() {
        var map = new google.maps.Map(document.getElementById('map'), {
          zoom: 13,
          center: {lat: 40.40926, lng: 49.86709}
        });

        var ctaLayer = new google.maps.KmlLayer({
          url: 'itdc.byethost7.com/BTM.kml',
          map: map
        });
      }

推荐答案

在github.com上为KML提供的链接的MIME类型为"text/plain",应为

The link provided for the KML on github.com is being served with a MIME type of "text/plain", it should be "application/vnd.google-earth.kml+xml"

3种KML MIME类型
响应来自Google Earth(或任何Earth浏览器)的请求时,KML服务器必须遵循一组规则,以便Google Earth能够正确解释其响应.

3 KML MIME Types
When responding to a request from Google Earth (or any Earth browser), a KML server must follow a certain set of rules so that Google Earth can correctly interpret its responses.

成功后,服务器必须返回HTTP 200的响应代码,并将响应的内容类型设置为适当的MIME类型,如此处所述.

Upon success, the server must return a response code of HTTP 200 and set the response's content-type to a suitable MIME type, as described here.

"Google地球"读取KML和KMZ文件. KML文件的MIME类型是 application/vnd.google-earth.kml + xml

Google Earth reads KML and KMZ files. The MIME type for KML files is application/vnd.google-earth.kml+xml

KMZ文件的MIME类型为
application/vnd.google-earth.kmz

The MIME type for KMZ files is
application/vnd.google-earth.kmz

验证器结果:

建议

此供稿是有效的,但可以通过实施以下建议来改善与最广泛的供稿阅读器的互操作性.

This feed is valid, but interoperability with the widest range of feed readers could be improved by implementing the following recommendations.

Feed不应与"text/plain"一起提供.媒体类型

Feeds should not be served with the "text/plain" media type

如果我将您的KML复制到我的服务器(该服务器以正确的MIME类型提供KML服务),则

If I copy your KML to my server (which serves KML with the correct MIME type), it works

BTW-如果我将验证器指向您问题代码中的链接,它根本不起作用,它不是KML文件,但是如果我将KmlLayer URL指向该链接,则

BTW - If I point the validator to the link in the code in your question, it doesn't work at all, it isn't a KML file, but if I point the KmlLayer URL to that, it also works

这篇关于Google Maps KML Layer无法读取kml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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