如何在网页上的谷歌地图中简单导入KML文件

时间:2014-04-01 20:58:58

标签: html html5 google-maps google-maps-api-3 kml

因此,我在Maps Engine Pro中生成了地图,导出了他们的KML文件,因为我已经阅读了您在Maps API中创建自定义地图的操作。

这里有一些我试图放在一起的屠宰代码,我似乎无法开始工作,但基本上我想弄清楚的是显示一个简单的地图,而不仅仅是地图引擎的链接所以它可以在以后操作(如聚类等)

<!DOCTYPE html>
<html>
    <script>


        var map;
        var src = 'https://developers.google.com/maps/tutorials/kml/westcampus.kml';

        function initialize() {
            map = new google.maps.Map(document.getElementById('map_canvas'), {
                center: new google.maps.LatLng(34.257753, -90.823688),
                zoom: 2,
                mapTypeId: google.maps.MapTypeId.HYBRID
            });
            loadKmlLayer(src, map);
        }

        function loadKmlLayer(src, map) {
            var kmlLayer = new google.maps.KmlLayer(src, {
                suppressInfoWindows: true,
                preserveViewport: false,
                map: map
            });
            google.maps.event.addListener(kmlLayer, 'click', function (event) {
                var content = event.featureData.infoWindowHtml;
                var testimonial = document.getElementById('capture');
                testimonial.innerHTML = content;
            });
        }

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

    </script>


<body>
    <div id="map" style="width:500px;height:500px;"></div>

</body>
</html>

0 个答案:

没有答案