如何在PHP中用KML创建KMZ?

时间:2014-05-07 06:03:45

标签: php gis kml kmz

我的KML尺寸越来越大,需要花费大量时间下载。我读到KMZ是非常压缩的版本,文件大小较少。我已经准备好了KML字符串。如何从KML字符串创建kmz文件?

1 个答案:

答案 0 :(得分:3)

这是一个用于动态创建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);

?>