使用php提取GPX数据,仅预测第一个结果

时间:2017-09-19 19:19:04

标签: php file foreach gpx

我想从gpx文件中提取数据,然后用php保存在mysql中,我写这个:

 $gpx = simplexml_load_file('uploads/unzip/'.$gpsfile.'/'.$gpxfile.'.gpx');
     foreach ($gpx->trk->trkseg->trkpt as $trkpt) {
         $lat = (string) $trkpt['lat'];
         $lon = (string) $trkpt['lon'];
         $name = (string) $gpx->trk->name;
         $desc = (string) $gpx->trk->desc;
         echo $lat;
         echo $lon;
         echo $desc;
       }

但是foreach功能它只显示了第一组trkpt coordonates。我需要使用所有trkpt coordonates返回所有trk部分。

文件有多个这样的trk部分:

    <trk>
      <name>test/name>
      <cmt>-</cmt>
      <desc>test</desc>
      <src>20--</src>
      <trkseg>
        <trkpt lat="44.867687980932203" lon="28.309019488759262">
        </trkpt>
        <trkpt lat="44.867702520087697" lon="28.308913064206525">
        </trkpt>
        <trkpt lat="44.867722086992117" lon="28.308743677250508">
        </trkpt>
        <trkpt lat="44.874962661538952" lon="28.311624759622379">
        </trkpt>
        <trkpt lat="44.87496253919776" lon="28.311625616880288">
        </trkpt>
        <trkpt lat="44.874914089738589" lon="28.311942660248032">
        </trkpt>
        <trkpt lat="44.874914070326035" lon="28.311942768555909">
        </trkpt>
        <trkpt lat="44.867687980932203" lon="28.309019488759262">
        </trkpt>
      </trkseg>
    </trk>
<trk>
      <name>test/name>
      <cmt>-</cmt>
      <desc>test</desc>
      <src>20--</src>
      <trkseg>
        <trkpt lat="44.867687980932203" lon="28.309019488759262">
        </trkpt>
        <trkpt lat="44.867702520087697" lon="28.308913064206525">
        </trkpt>
        <trkpt lat="44.867722086992117" lon="28.308743677250508">
        </trkpt>
        <trkpt lat="44.874962661538952" lon="28.311624759622379">
        </trkpt>
        <trkpt lat="44.87496253919776" lon="28.311625616880288">
        </trkpt>
        <trkpt lat="44.874914089738589" lon="28.311942660248032">
        </trkpt>
        <trkpt lat="44.874914070326035" lon="28.311942768555909">
        </trkpt>
        <trkpt lat="44.867687980932203" lon="28.309019488759262">
        </trkpt>
      </trkseg>
    </trk>

0 个答案:

没有答案