【问题标题】:How to create KMZ from KML in PHP?如何在 PHP 中从 KML 创建 KMZ?
【发布时间】:2014-05-07 06:03:45
【问题描述】:

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

【问题讨论】:

标签: php gis kml kmz


【解决方案1】:

这是一个 php 代码,用于从 KML 动态创建 KMZ 文件。我的 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);

?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    相关资源
    最近更新 更多