-1

I have a set of multiple lng/lat Points where I'm trying to find the one closest to my origin lng/lat. I do not need any distance calculated, only find the point which is the closest to my origin in airdistance.

I need however to take into account if any of the set may be on the other side of the Meridian aswell.

So say I have my current data:

$origin = array( "lat" => 52.3702157, "lng" => 4.8951679 );

$the_rest = array(
 array( "lat" => 52.5200066,
        "lng" => 13.404954
),
array(
        "lat" =>  48.856614,
        "lng" => 2.3522219

)

);

My initial thought was just to loop through all set and do a simple subtraction of the lat/lng from my origin and see which yeilds the lowest difference. But this does not take into account the Meridian issue.

Sjobi
  • 7
  • 1
  • 5

1 Answers1

0
function airDistance($latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo){
$theta = $longitudeFrom - $longitudeTo;
$dist = sin(deg2rad($latitudeFrom)) * sin(deg2rad($latitudeTo)) +  cos(deg2rad($latitudeFrom)) * cos(deg2rad($latitudeTo)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$meters = $dist * 111.18957696;
return $meters;}

This is system to get distance in the coordinate system without use google maps. It's faster because it's not loading from the google maps API.

Ok Ram
  • 41
  • 5