Relative Position in PHP between 2 points (Lat/Long)

Posted by Brian H on Stack Overflow See other posts from Stack Overflow or by Brian H
Published on 2010-05-18T18:17:18Z Indexed on 2010/05/18 18:20 UTC
Read the original article Hit count: 289

I have a database of airports with Latitude and Longitude for each point. I want to run a PHP script to find all airports that are nearby a given airport, with their distance and relative direction.

I.e. for Airport KLDJ (40-37-02.810N 074-14-40.539W)

Airport Nearby
KJFK - John F Kennedy Airport (21.2 nm NE) (40-38-23.104N 073-46-44.132W)

I have used code from http://www.movable-type.co.uk/scripts/latlong.html to find distance, and tried to use it to find bearing, which might not be right.

//BEARING RHUMB LINE
$phi = log(tan($lat2/2+pi/4)/tan($lat1/2+pi/4));
$distance['bearing'] = (rad2deg(atan2($theta, $phi)) +180) % 360;

I basically want to run all points through this script and find the distance, which I have already, but then the direction. (i.e. N, S, W, E, NW, SW, NE, SE)

© Stack Overflow or respective owner

Related posts about php

Related posts about distance