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

Overview

GreatCircle

A set of three functions, useful in geographical calculations of different sorts. Available for PHP, Python, Javascript and Ruby.

Live demo of the JavaScript implementation.

Usage with node.js

Install npm module great-circle

npm install great-circle

Usage in node.js or with browserify

var GreatCircle = require('great-circle')

Distance

Takes two sets of geographic coordinates in decimal degrees and produces distance along the great circle line. Output in kilometers by default.

PHP:

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

Python:

print( GreatCircle.distance(51.507222, -0.1275, 48.8567, 2.3508) )

JavaScript:

document.write ( GreatCircle.distance(51.507222, -0.1275, 48.8567, 2.3508) );

Ruby

puts GreatCircle.distance(51.507222, -0.1275, 48.8567, 2.3508)

Optional fifth argument allows to specify desired units:

  • M - meters
  • KM - kilometers
  • MI - miles
  • NM - nautical miles
  • YD - yards
  • FT - feet
// Distance from JFK airport to La Guardia airport in feet
echo GreatCircle::distance(40.63980103, -73.77890015, 40.77719879, -73.87259674, "FT");
// Output: 56425.612628758

The optional argument can also be passed in form of planet radius in any unit, to produce output in this unit.

// Distance between North and South poles on Mars (3389.5 is mean radius of Mars in kilometers)
echo GreatCircle::distance(90, 0, -90, 0, 3389.5);
// Output: 10648.428299343
// Distance between Moscow and New York in furlongs (31670.092 is Earth radius in furlongs)
echo GreatCircle::distance(55.75, 37.616667, 40.7127, -74.0059, 31670.092);
// Output: 37335.295755141

Bearing

Takes two sets of geographic coordinates in decimal degrees and produces bearing (azimuth) from the first set of coordinates to the second set.

// Bearing from Paris to London in decimal degrees
echo GreatCircle::bearing(48.8567, 2.3508, 51.507222, -0.1275);
// Output: 330.03509575101

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.

// Coordinates of a location 100 KM away from Paris, traveling in the direction of London
$dest = GreatCircle::destination(48.8567, 2.3508, 330.035, 100);
printf("Latitude: %f, Longitude: %f", $dest["LAT"], $dest["LON"]);
// Output: Latitude: 49.633753, Longitude: 1.657274

Just like Distance, Destination assumes entered distance is in kilometers, but takes an optional argument to specify desired unit.

// Coordinates of a location 500 nautical miles away from Paris, traveling in the direction of New York
$brg = GreatCircle::bearing(48.8567, 2.3508, 40.7127, -74.0059);
$dest = GreatCircle::destination(48.8567, 2.3508, $brg, 500, "NM");
printf("Latitude: %f, Longitude: %f", $dest["LAT"], $dest["LON"]);
// Output: Latitude: 51.306719, Longitude: -10.071875
You might also like...

Generate meshes from signed distance functions and constructive solid geometry operations.

Generate meshes from signed distance functions and constructive solid geometry operations.

sdf-csg Generate meshes from signed distance functions and constructive solid geometry operations. This library is heavily based upon Inigo Quilez's 3

Oct 24, 2022

Free to read e-paper with concise articles and many categories

Free to read e-paper with concise articles and many categories

THE FREE TIMES About The free times is a free-to-read e-paper with concise articles and many categories. My aim is to provide a nice newspaper like ex

Dec 16, 2022

⏱ Simple Alpine.js plugin to display the human-readable distance between a date and now.

⏱ Alpine TimeAgo ⏱ An Alpine.js plugin to return the distance between a given date and now in words (like "3 months ago", "about 2 hours ago" or "in a

Dec 22, 2022

Open-source project inspired by the idea of "Long Distance Lamp"

Open-source project inspired by the idea of

Project inspired by the idea of Long Distance Lamp (e.g. Friendship Lamps) for people with no soldering skills.

Mar 19, 2022

Ruby's rstfilter extension

Ruby's rstfilter extension

vscode-rstfilter README You can see the execution results by saving the file. Requirements rstfilter-lsp command in rstfilter gem is needed. $ gem ins

Dec 27, 2022

Lightweight VSCode extension for Ruby.

Lightweight VSCode extension for Ruby.

vscode-ruby-light Lightweight VSCode extension for Ruby. Install Install via Visual Studio Marketplace: Ruby Light - Visual Studio Marketplace For Dia

Jan 2, 2023

A comprehensive collection of useful tools developed with the help of Ethers.js to interact with the Ethereum Blockchain to develop great DeFi apps as quickly and easily as possible.

hudi-packages-ethersfactory How to install Installing with npm For more information on using npm check out the docs here. npm i @humandataincome/ether

Mar 30, 2022

Collection of custom elements that appear hand drawn. Great for wireframes or a fun look.

Collection of custom elements that appear hand drawn. Great for wireframes or a fun look.

wired-elements 👉 wiredjs.com Wired Elements is a series of basic UI Elements that have a hand drawn look. These can be used for wireframes, mockups,

Jan 7, 2023

Calculate the price range for property advertised on Domain and Real Estate.

Calculate the price range for property advertised on Domain and Real Estate.

Property Seeker Calculate the price range for property advertised on Domain and Real Estate. Install Chrome Firefox Edge Privacy All searches are perf

Dec 27, 2022
Comments
  • question about bearing

    question about bearing

    Is the bearing the compass bearing at point A to begin the great circle/geodesic route to point B?

    Is there an easy way to get compass bearings as a function of distance traveled from point A? (i.e. along the entire route, from the outset?)

    Obviously any nav-guidance system could just recalculate bearing at each location as it transits the great circle, but I'm curious if your tool can provide this info at the outset.

    Thanks!

    opened by zbeekman 1
Owner
null
Quick One Liners in JavaScript, TypeScript, Python, Rust, Java, Ruby, C, C++

ONE LINERS This repository contains cool and simple one line utility functions to easily use common repetitive methods in JavaScript, TypeScript, Pyth

Divin Irakiza 3 Mar 2, 2022
A status monitor for Elite Dangerous, written in PHP. Designed for 1080p screens in the four-panel-view in panel.php, and for 7 inch screens with a resolution of 1024x600 connected to a Raspberry Pi.

EDStatusPanel A status monitor for Elite Dangerous, written in PHP. Designed for 1080p screens in the four-panel-view in panel.php, and for 7 inch scr

marcus-s 24 Oct 4, 2022
caniuse.com but for PHP - a searchable list of new and deprecated features in recent PHP versions

caniphp.com caniphp.com is like caniuse.com but for PHP features. It's a simple search of PHP features that added, deprecated and removed in recent ve

Ross Wintle 95 Dec 25, 2022
A great result management solution for schools, hospital, academy and other. If you are a php developer, contribute to this respository for more advancement of the project.

result-management-pro A great result management system for schools, hospital, academy and more. Contributions Willing to add more features to this gre

Adeleye Ayodeji 8 Jun 17, 2022
🤖 Tailwind CSS assistant helps you to edit classes (includes JIT & ignores purge), toggle breakpoint classes on an element and view current breakpoint

Tailwind CSS Assistant See it in action on this example website ?? ✅ Small JavaScript package that helps you work with Tailwind CSS by... Showing you

Mark Mead 30 Dec 28, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
This is a project that is used to execute python codes in the web page. You can install and use it in django projects, You can do any operations that can be performed in python shell with this package.

Django execute code This is a project that is used to execute python codes in the web page. You can install and use it in django projects, You can do

Shinu 5 Nov 12, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Break the barrier of your country, language and distance...

HACK ON 2.0 PROJECT METAFRATIS Break the barrier of your country, language and distance... PROBLEM OUR PROJECT SOLVES With the onset of Covid-19 we ha

Snehasish Dhar 16 Jul 6, 2021