0

我想使用 Geoxml3 在 googlemap 上加载 kmlfile,googlemap 已加载但未显示图层,我不知道我的代码有什么问题,谁能帮忙?

<script type="text/javascript">
var mapInstance;
var parser;

function doAlert() {
        alert("Parsed triggered!");
}

function initialize() {
        console.log("in init");
        var latlng = new google.maps.LatLng(41.1188827, 1.24449090);
        var mapOptions = {
                zoom: 14,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                mapTypeControlOptions: {
                style: google.maps.MapTypeControlStyle.DEFAULT
                }
        };
        mapInstance = new google.maps.Map(document.getElementById("map"), mapOptions);
        parser = new geoXML3.parser({
                map: mapInstance,
                zoom: false,
                processStyles: true,
                singleInfoWindow: true
                }
        );
        google.maps.event.addListener(parser, 'parsed', doAlert);       
        parser.parse('postes.kml');
}               
</script>
</head>
<body onload="initialize()">
        <div id="map" style="width: 100%; height: 100%"></div>
</body>
</html>
4

1 回答 1

0

您不创建标记,您只解析 kml 但不将其设置为地图。这是来自https://code.google.com/p/geoxml3/wiki/Usage的一些示例代码

<script type="text/javascript">
    var myMap = new google.maps.Map(...);

    var myParser = new geoXML3.parser({
      map: myMap,
      processStyles: true,
      createMarker: addMyMarker,
      createOverlay: addMyOverlay
    });
    myParser.parse(['my_geodata1.kml', 'my_geodata2.kml']);

    function addMyMarker(placemark) {
      // Marker handling code goes here
      if (someCondition) {
        myParser.createMarker(placemark);
      }
    };

    function addMyOverlay(groundOverlay) {
      // Overlay handling code goes here
      if (someCondition) {
        myParser.createOverlay(groundOverlay);
      }
    };
  </script>
于 2014-05-14T11:23:05.057 回答