fixed handling with empty gpx files

This commit is contained in:
surrim 2021-07-12 23:24:23 +02:00 committed by onli
parent 8af5e65de2
commit 8f778c4119

View file

@ -48,11 +48,11 @@
$tmpFile = tmpfile();
fwrite($tmpFile, '<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><gpx version="1.1" creator="surrim.org" xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">');
$gpx = simplexml_load_file($fileName);
foreach ($gpx->trk as $trk) {
foreach (($gpx->trk ?? []) as $trk) {
fwrite($tmpFile, '<trk>');
foreach($trk->trkseg as $seg) {
foreach (($trk->trkseg ?? []) as $seg) {
fwrite($tmpFile, '<trkseg>');
foreach($seg->trkpt as $pt) {
foreach (($seg->trkpt ?? []) as $pt) {
fwrite($tmpFile, '<trkpt lat="'.$pt['lat'].'" lon="'.$pt['lon'].'"><ele>'.$pt->ele.'</ele></trkpt>');
}
fwrite($tmpFile, '</trkseg>');