Skip to content

Haversine formula in JS.

License

Notifications You must be signed in to change notification settings

alejandrotrevi/Haversine-JS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Haversine

Haversine formula

English

Original implementation and credits: Movable Type

Installation

You have two options to use the script:

Bower
  • Installing Bower: Bower
  • bower install haversine-js
  • include haversine.min.js in your html.
Manual
  • Download script Github
  • Include haversine.min.js in your html.

Usage

Just give getDistance() two coordinates in this format:

getDistance({lat: 18.469510, lng: -98.257464}, {lat: 17.250959, lng: -95.283587});

The function returns the distance in meters, you can transform the distance to km like this:

Math.round((distance / 1000) * 10) / 10

Where distance is of course the distance in meters.

Español

Implementación original y créditos: Movable Type

Instalación

Tienes dos opciones para usar el script:

Bower
  • Instalar bower Bower
  • bower install haversine-js
  • Incluir haversine.min.js en tu html
Manual
  • Descargar script Github
  • Incluir haversine.min.js en tu html.

Uso

Dale a getDistance() dos coordenadas en este formato:

getDistance({lat: 18.469510, lng: -98.257464}, {lat: 17.250959, lng: -95.283587});

La función retorna la distancia en metros, si quieres transformarla a km puedes hacer lo siguiente:

Math.round((distance / 1000) * 10) / 10

Donde distance es desde luego la distancia en metros.