Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我的KML文件无法处理Javascript代码_Javascript_Google Maps_Kml - Fatal编程技术网

我的KML文件无法处理Javascript代码

我的KML文件无法处理Javascript代码,javascript,google-maps,kml,Javascript,Google Maps,Kml,当我尝试添加我从google maps导出的文件“myFile.kml”时,它不会显示我的地图的任何路径,而google“”中的示例可以正常工作吗? 你知道我错过了什么吗 这是我的HTML代码: <!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <title></title> <style type="text/css

当我尝试添加我从google maps导出的文件“myFile.kml”时,它不会显示我的地图的任何路径,而google“”中的示例可以正常工作吗? 你知道我错过了什么吗

这是我的HTML代码:

<!DOCTYPE html>
<html lang="en" >
<head>
    <meta charset="UTF-8">
    <title></title>
    <style type="text/css">
        html, body {
            height: 100%;
            margin: 0;
            padding: 0;
        }
        #map {
            height:100%
        }
    </style>
</head>
<body >


    <div id="map"></div>

<script src="https://maps.googleapis.com/maps/api/js?signed_in=true&callback=initMap"></script>
<script src="script.js"></script>
</body>
</html>

似乎您正试图从本地主机或本地文件系统加载KML文件

如果是这样,基本上您有两个选择:

  • 将KML文件放在google server所在的公共服务器上 可以到达,因为KML的解析和呈现是由 谷歌服务器
  • 利用它可以加载KML文件和 在localhost上解析它(参见下面的示例)
示例

该示例演示如何使用以下命令从localhost加载和解析KML文件:

在HTML文件中添加对的引用,例如:

<script type="text/javascript" src="http://geoxml3.googlecode.com/svn/branches/polys/geoxml3.js"></script>


您正在尝试从本地主机访问您的文件吗?
var map;
function initMap() {
    map = new google.maps.Map(document.getElementById('map'), {
        center: { lat: 41.876, lng: -87.624 },
        zoom: 10
    });


    var myParser = new geoXML3.parser({ map: map });
    myParser.parse('cta.kml');
}
<script type="text/javascript" src="http://geoxml3.googlecode.com/svn/branches/polys/geoxml3.js"></script>