dpylt7626401 2016-06-01 16:57
浏览 62

如何正确计算gpx文件的距离 - php

What am I doing wrong ? I'm, trying to count distances from a gpx (lat, lon) file but I receives wrong result.

function distance($lat1, $lon1, $lat2, $lon2) {
   $theta = $lon1 - $lon2;
   $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +  cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
   $dist = acos($dist);
   $dist = rad2deg($dist);
   $kilometers = $dist * 60 * 1.1515 ;
   return $kilometers;
}

$gpx_file_source = simplexml_load_file($gpx_patch);
$j=0;
foreach($gpx_file_source->trk->trkseg->trkpt as $point){
        if($j%2==0){
             $lat1=$point->attributes()[0];
             $lon1=$point->attributes()[1];
        }else{
             $lat2=$point->attributes()[0];
             $lon2=$point->attributes()[1];
             $totaldistance=distance(''.$lat1.'', ''.$lon1.'', ''.$lat2.'', ''.$lon2.'').;
             $totaldistance+=$totaldistance;
        }   
  $j++;
}
echo $totaldistance; //0.00011797444243905

My result is: 0.00011797444243905 km

Correct result: 17.35 km

GPX file: http://itros.us/distance.gpx

  • 写回答

1条回答 默认 最新

  • dqkf36241 2016-06-01 21:54
    关注

    I changed counting function and is working !

    3958*3.1415926*sqrt(($lat2-$lat1)*($lat2-$lat1) + cos($lat2/57.29578)*cos($lat1/57.29578)*($lon2-$lon1)*($lon2-$lon1))/180
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?