问题描述
有什么方法可以在Google地图中使用KMZ文件吗?我的KML文件大约为10.7MB,因此无法在Google地图上加载。 KMZ文件大约2MB。我看到的唯一方法是拥有多个KML,但工作量太大。我可能会这样做,但只是想知道是否可以使用KMZ?
谢谢。
是的,您可以使用Maps API指定KMZ文件:
var kmzLayer = new google.maps.KmlLayer( 'http://www.kmzlinks.com/redirect.asp?id=110&file=PalmIsland%2Ekmz');
kmzLayer.setMap(map);
在您的特定情况下,您的脚本应该如下所示:
< script type =text / javascript>
函数initialize(){
var myOptions = {
center:new google.maps.LatLng(58.33,-98.52),
zoom:11,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById(map_canvas),myOptions);
var kmzLayer = new google.maps.KmlLayer('http://xeenat.com/energy/data.kmz');
kmzLayer.setMap(map);
}
< / script>
但是 - 您的KML太大了。尽管它被压缩为2MB作为KMZ,但Maps在解压缩后会查看它的大小,在您的情况下大于10MB。尝试将它缩减一点 - 如果您将KMZ网址替换为上面第一个代码段中的网址,它将起作用。看起来你需要使用多个KML文件。也许您可以将KMZ加载到Google地球中,然后将每个省份保存为自己的文件(右键单击地球地点标签中的文件夹,然后选择另存为...)
Is there any way I can use a KMZ file in Google Maps? My KML file is around 10.7MB so it doesn't load on Google Maps. KMZ file is around 2MB. The only way I see it is to have multiple KML but it's too much work. I might end up doing that, but was just wondering if KMZ can be used?
Thanks.
Yes, you can specify a KMZ file using the Maps API:
var kmzLayer = new google.maps.KmlLayer('http://www.kmzlinks.com/redirect.asp?id=110&file=PalmIsland%2Ekmz');
kmzLayer.setMap(map);
In your specific case, your script should look like this:
<script type="text/javascript">
function initialize() {
var myOptions = {
center: new google.maps.LatLng(58.33, -98.52),
zoom: 11,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var kmzLayer = new google.maps.KmlLayer('http://xeenat.com/energy/data.kmz');
kmzLayer.setMap(map);
}
</script>
BUT - your KML is too big. Even though it's compressed down to 2MB as a KMZ, Maps looks at the size after it's been decompressed, and in your case that's bigger than 10MB. Try cutting it down a bit - if you replace your KMZ URL with the one in the first snippet above, it will work. Looks like you'll need to use multiple KML files. Perhaps you could load the KMZ into Google Earth, then save each province as its own file (right-click on the folder in Earth's "Places" tab, and select Save as...)
这篇关于在Google地图中使用KMZ文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!