Why not doesn't Google maps view the kml layout?

只谈情不闲聊 提交于 2019-12-20 07:38:09

问题


I do this tutorial. I copied the source code from here. I use the similar .kml file too!

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
    <script>
        function initialize() {
            var chicago = new google.maps.LatLng(41.875696, -87.624207);
            var mapOptions = {
                zoom: 11,
                center: chicago,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            }

            var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

            var ctaLayer = new google.maps.KmlLayer({
                url: 'https://de-ik-kml.googlecode.com/svn/trunk/cta.kml'
            });
            ctaLayer.setMap(map);
        }

        google.maps.event.addDomListener(window, 'load', initialize);

    </script>

But when I would like to use my url, the google maps doesn't load or view the .kml file. I don't understand why don't.

The Developer tool of Chrome doesn't show any errors. So I can't debug what is the problem. I don't find. I tried that I replace the 'https' to 'http', but this isn't solve my problem. I just changed only the url javascript variable's value in my code.

Here is my .kml file online


回答1:


Your file from SVN has the wrong content type in the headers:

Content-Type:·text/plain

See this issue and this question on SO for more details.

The mime-type for KML needs to be application/vnd.google-earth.kml+xml

This may also be helpful

Set the mime type of all to be application/vnd.google-earth.kml+xml using svn propset svn:mime-type 'application/vnd.google-earth.kml+xml' *.kml (thanks to http://manjeetdahiya.com/2010/09/29/serving-html-documentation-from-google-code- svn/ for the tip).



来源:https://stackoverflow.com/questions/19501713/why-not-doesnt-google-maps-view-the-kml-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!