Skip to content

A concise collection of classes for PHP, Python, JavaScript, Ruby and Go to calculate great circle distance, bearing, and destination from geographic coordinates

License

Notifications You must be signed in to change notification settings

mwgg/GreatCircle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

GreatCircle

A set of three functions, useful in geographical calculations of different sorts.

####Distance Takes two sets of geographic coordinates in decimal degrees and produces distance along the great circle line. Output in KM by default, specify Earth radius as fifth argument in unit other than KM to produce output in that unit. ####Bearing Takes two sets of geographic coordinates in decimal degrees and produces bearing (azimuth) from the first set of coordinates to the second set. ####Destination Takes one set of geographic coordinates in decimal degrees, azimuth and distance to produce a new set of coordinates, specified distance and bearing away from original. Output in KM by default, specify Earth radius as fifth argument in unit other than KM to produce output in that unit.

##Example

// Distance from London to Paris
echo GreatCircle::distance(51.507222, -0.1275, 48.8567, 2.3508);
// Output: 343.46748684413

// Same distance in miles by specifying Earth radius in miles
echo GreatCircle::distance(51.507222, -0.1275, 48.8567, 2.3508, 3959);
// Output: 213.43396333635
    
// Bearing from Paris to London in decimal degrees
echo GreatCircle::bearing(48.8567, 2.3508, 51.507222, -0.1275);
// Output: 330.03509575101
    
// Coordinates of a location 100 KM away from Paris, traveling in the direction of London
$dest = GreatCircle::destination(48.8567, 2.3508, 330, 100);
printf("Latitude: %f, Longitude: %f", $dest["LAT"], $dest["LON"]);
// Output: Latitude: 49.633476, Longitude: 1.656542

About

A concise collection of classes for PHP, Python, JavaScript, Ruby and Go to calculate great circle distance, bearing, and destination from geographic coordinates

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published