Google 地图 KML 图层无法读取 kml
Google Maps KML Layer won't read kml
我正在尝试使用 Google 地图 API 读取一个简单的 KML 3,我在 Google 地图编辑器中创建了 KML 文件,代码是 google 示例,我找不到哪里有问题。
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 提供的 link 正在使用“text/plain”的 MIME 类型提供,它应该是 "application/vnd.google-earth.kml+xml"
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.
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 Earth reads KML and KMZ files. The MIME type for KML files is
application/vnd.google-earth.kml+xml
The MIME type for KMZ files is
application/vnd.google-earth.kmz
Recommendations
This feed is valid, but interoperability with the widest range of feed readers could be improved by implementing the following recommendations.
Feeds should not be served with the "text/plain" media type
如果我将您的 KML 复制到我的服务器(以正确的 MIME 类型提供 KML),it works
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 地图 API 读取一个简单的 KML 3,我在 Google 地图编辑器中创建了 KML 文件,代码是 google 示例,我找不到哪里有问题。
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 提供的 link 正在使用“text/plain”的 MIME 类型提供,它应该是 "application/vnd.google-earth.kml+xml"
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.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 Earth reads KML and KMZ files. The MIME type for KML files is application/vnd.google-earth.kml+xml
The MIME type for KMZ files is
application/vnd.google-earth.kmz
Recommendations
This feed is valid, but interoperability with the widest range of feed readers could be improved by implementing the following recommendations.
Feeds should not be served with the "text/plain" media type
如果我将您的 KML 复制到我的服务器(以正确的 MIME 类型提供 KML),it works
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