如何从多个经纬度坐标计算距离?

时间:2019-05-27 16:50:28

标签: php arrays geolocation distance latitude-longitude

我有以下数组:

$latitude = ['9.9663755','10.1883153','9.9689272','10.1109653' ,'10.1883153','10.1883153']
$longitude = ['76.288569','76.4512288','76.2890601','76.3541268','76.4512288','76.4512288']

如何获得这些点的总行驶距离。

1 个答案:

答案 0 :(得分:0)

除了数组处理外,它是Measuring the distance between two coordinates in PHP的副本(用于计算距离)。我建议像这样:

$dist=0;
$alen=count($latitude);

for ($i=1;$i<$alen;$i++) {
   $lat=$latitude[$i];
   $lon=$longotude[$i];
   $frlat=$latitude[$i-1];
   $frlon=$longotude[$i-1]
  // calculate distance according to the link above
  // pass in $frlat, $frlon and $lat, $lon to determine a single
  // segment distance. store in $calcdist)
  $dist+=$caldist;
  $llat=$lat;
  $
}