我的 KML 大小越来越大,下载需要很长时间。我读到 KMZ 是非常压缩的版本,并且文件大小较小。我已经准备好 KML 字符串。如何从 KML 字符串创建 kmz 文件?
最佳答案
这里是一个 PHP 代码,用于从 KML 动态创建 KMZ 文件。我的 KML 6.0 Mb 减少到 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);
?>
关于php - 如何在 PHP 中从 KML 创建 KMZ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23509909/