0

I have the following arrays:

$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']

How do I get the total distance travelled with these points.

Emma
  • 27,428
  • 11
  • 44
  • 69
  • Somewhat off topic but *"longotude"* isn't spelt properly, it should be *"longitude"*. – Malekai May 27 '19 at 17:03
  • lat and long having totally four points FROM and TO. Why you are having 6,6? – Rasa Mohamed May 27 '19 at 17:08
  • This site is not coding service - please try to do that yourself (and share the code you tried) and if you failed I will post the php code of how to do it – dWinder May 27 '19 at 17:15

1 Answers1

0

Except for the array handling this is a duplicate of Measuring the distance between two coordinates in PHP (to calculate the distance). I would suggest something like:

$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;
  $
}
mlewis54
  • 2,372
  • 6
  • 36
  • 58
  • Rasa Mohmed -- Your proposed edit does not take into account that the loop should only be run 4 times since the first element in the array is the starting point. So you are adding 1-0, 2-1, 3-2 and 4-3 elements to get the distance that's why $i<$alen is used instead of $i<=$alen as you suggest. – mlewis54 May 28 '19 at 14:22