Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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
        });
      }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
143 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

validator results:

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

If I copy your KML to my server (which serves KML with the correct MIME type), 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...