function download_kml($call, $startdatestr, $enddatestr) { global $mysqli; date_default_timezone_set("Asia/Shanghai"); header("Content-Type:application/gpx+xml"); header("Content-Disposition:attachment; filename=\"" . $call . "-" . $startdatestr . "Track.kml\""); echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; echo "<kml xmlns=\"http://www.opengis.net/kml/2.2\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\">\n"; echo "<Document>\n"; echo "<name>" . $call . " Track</name>\n"; ?> <Style id="ylw"> <LabelStyle> <color>ff1307ff</color> </LabelStyle> <LineStyle> <color>ff00ffff</color> <width>4</width> </LineStyle> </Style> <?php echo "<Folder><name>" . $call . "-" . $startdatestr . "</name>\n"; echo "<Placemark>\n"; echo "<styleUrl>#ylw</styleUrl>\n"; echo "<gx:Track id=\"1\">\n"; echo "<altitudeMode>absolute</altitudeMode>\n"; $q = "select date_format(CONVERT_TZ(tm,@@session.time_zone, '+00:00'),\"%Y-%m-%dT%H:%i:%sZ\"),lat,lon,msg,datatype from aprspacket where tm>=? and tm<=? and `call`=? and lat<>'' and not lat like '0000.00%' order by tm"; $stmt = $mysqli->prepare($q); $stmt->bind_param("sss", $startdatestr, $enddatestr, $call); $stmt->execute(); $stmt->bind_result($dtm, $glat, $glon, $msg, $ddt); $stmt->store_result(); while ($stmt->fetch()) { echo "<when>" . $dtm . "</when>\n"; } $stmt->data_seek(0); while ($stmt->fetch()) { $lat = strtolat($glat); $lon = strtolon($glon); // $wpt = gpx_wpt($dtm, $msg,$ddt); echo "<gx:coord>" . $lon . " " . $lat . " "; echo kml_alt($msg); echo "</gx:coord>\n"; } echo "</gx:Track>\n"; echo "</Placemark>\n"; echo "</Folder>\n"; echo "</Document>\n"; echo "</kml>\n"; exit(0); }
// GPS 高度 echo " <altitudeMode>absolute</altitudeMode>\n"; } else { echo " <altitudeMode>clampToGround</altitudeMode>\n"; } echo " <coordinates>\n"; while ($stmt2->fetch()) { if (!checklatlon($glat, $glon)) { continue; } $lat = strtolat($glat); $lon = strtolon($glon); echo $lon . "," . $lat . ","; if ($altmode == 0) { // GPS 高度 echo kml_alt($msg, $ddt); } else { echo "0"; } echo " "; } echo " </coordinates>\n"; echo " </LineString>\n"; } } echo " </MultiGeometry>\n"; echo "</Placemark>\n"; } ?> </Document>