php - Get in between lat long from two lat long and direction -


i working on 1 application need in between lat long 2 lat long.

so have

1) lat long of start point

2) lat long of end point

3) direction, south(180 degree) or north(0 degree)

4) distance between 2 points

now divide whole path in number of chunks, divide whole path 10 km.

so lets total distance 100km 10 chunks.

if 200km there 20 chunks.

so want find out point's lat long 2 lat long.

so 20 points should in 1 line , @ equal distance.

how achieve ?

you can try taking difference between 2 lat lon points, dividing them number of chunks. give "increment". can added, or taken away depending on direction, in loop create points in between.

consider following did test:

//position 1 $lat1 = 53.2226754; $lon1 = 0.124584;  //position 2 $lat2 = 52.212445; $lon2 = -0.12458;  //differences in lat / lon $latdif = round($lat1 - $lat2, 7); $londif = round($lon1 - $lon2, 7);  //calculate step / increment //i used 10 example number of steps $chunks = 10; $latstep = round($latdif / $chunks, 7); $lonstep = round($londif / $chunks, 7);  //new lat lon starts @ start point $newlat = $lat1; $newlon = $lon1;   echo $lat1 . ", " . $lon1 . "<br>"; //start point  for($i = 1; $i < $chunks; $i++){      //direction substituted here      if($lat1 < $lat2){         $newlat = $newlat + $latstep; //going north     } else {         $newlat = $newlat - $latstep; //going south     }      if($lon1 < $lon2){         $newlon = $newlon + $lonstep; //going east     } else {         $newlon = $newlon - $lonstep; //going west     }      echo $newlat . ", " . $newlon . "<br>"; //new point }  echo $lat2 . ", " . $lon2 . "<br>"; //end point 

this leads following lat lon output:

53.2226754, 0.124584;
53.1216524, 0.0996676;
53.0206294, 0.0747512;
52.9196064, 0.0498348;
52.8185834, 0.0249184;
52.7175604, 0.0000002;
52.6165374, -0.0249144;
52.5155144, -0.0498308;
52.4144914, -0.0747472;
52.3134684, -0.0996636;
52.212445, -0.12458;

i plotted these on online geoplanner , got following:

geoplanner output of lat lon

gps results link


Comments