2

我的 KML 大小越来越大,需要很长时间才能下载。我读到 KMZ 是非常压缩的版本,文件大小更小。我已经准备好 KML 字符串。如何从 KML 字符串创建 kmz 文件?

4

1 回答 1

4

这是一个从 KML 动态创建 KMZ 文件的 php 代码。我的 6.0 Mb 的 KML 减少到 600Kb。您还可以在这里找到答案http://shprabin.wordpress.com/2013/06/24/creating-kmz-file-on-the-fly-php/

<?php

header('Content-Type: application/vnd.google-earth.kmz');
header('Content-Disposition: attachment; filename="test.kmz"');

$kmlString="This is your KML string";

$file = "test.kmz";
$zip = new ZipArchive();

if ($zip->open($file, ZIPARCHIVE::CREATE)!==TRUE) {
exit("cannot open <$file>\n");
}
$zip->addFromString("doc.kml", $kmlString);
$zip->close();
echo file_get_contents($file);

?>
于 2014-05-07T06:07:57.357 回答