我有一个看起来像这样的KMZ文件:
example.kmz:
->example.png
->example.kml
example.kml:
<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document id="root_doc">
<Schema name="test" id="test">
<SimpleField name="ID1" type="int"></SimpleField>
</Schema>
<Folder>
<name>Ground Overlays</name>
<visibility>0</visibility>
<description>Examples of ground overlays</description>
<GroundOverlay>
<name>example overlay</name>
<visibility>0</visibility>
<description>Overlay example png.</description>
<Icon>
<href>example.png</href>
</Icon>
<LatLonBox>
<north>50.080654</north>
<south>50.079959</south>
<east>19.993121</east>
<west>19.992118</west>
<rotation>0.0</rotation>
</LatLonBox>
</GroundOverlay>
</Folder>
</Document>
</kml>
和这样的JS代码:
var map = new google.maps.Map(document.getElementById('mapDiv'), {
zoom: 11,
minZoom: 1,
streetViewControl: false
});
//adding kmz layer from file
var kmzLayer = new google.maps.KmlLayer('/kml/example.kmz');
kmzLayer.setMap(map);
var markers = [];
var bounds = new google.maps.LatLngBounds();
//adding markers
// Automatically center the map fitting all markers on the screen
map.fitBounds(bounds);
问题是,地图生成正常,标记正常,但控制台中没有错误,而KMZ文件中的groundOverlay没有呈现在地图上。
我找不到原因-我想念什么?我手动创建了KMZ文件-也许我错过了一些东西吗?但是,为什么没有错误呢?
感谢帮助
EDIT1我使用elsevier-apps.sciverse.com/GoogleMaps/verification在线验证器检查了KMZ文件-一切正常。
因此,事实证明-您无法使用本地KML / KMZ文件。所有文件都必须公开访问,并且您应该在其中添加工作网址new google.maps.KmlLayer(VALID_URL);
或者...
您可以使用geoxml3解析本地KMZ / KML文件。
因此,现在一切正常:)我的KMZ文件是正确的,我的JS代码也是正确的(除了我上面描述的这一部分)。我希望它能对某人有所帮助:)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句