JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 622
  • Score
    100M100P100Q101686F
  • License MIT

Get distance between any two latitute/longitude coordinates

Package Exports

  • s-haversine

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (s-haversine) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

s-haversine

NPM version Dependencies build status NPM license

About

This module calculates the distance between two points on Earth using lat/long coordinates. It is based on the haversine formula and includes a utility to convert from degrees/minutes/seconds to the signed decimal degrees format needed for the formula to work.

This can be used with the web Geolocation API, which provides lat/long coordinates.

Usage

Get a pair of latitude/longitude coordinates then use them as the arguments for the distance method. Example:

import haversine from 's-haversine';

// ---------- [latitude, longitude];
const coords1 = [36.151829, -115.143296];
const coords2 = [36.151465, -115.146284];

haversine.distance(coords1, coords2); // 271.314... (meters)

Converting deg/min/sec to decimal

This module requires coordinates to be in a signed decimal format. If you have coordinates in degrees/minutes/seconds (DMS) format, use the dmsToDecimal method to convert them. For example, an input such as 40 20 50W or 40°20'50" S will return roughly -40.34722.

havesine.dmsToDecimal('40 20 50W'); // -40.34722... (degrees)

Earth radius

The math involved in the haversine formula depends on knowledge of the Earth's radius. This is configured by default as 6371000 (in meters). If you need to fine tune this or use another radius, you can configure this by setting haversine.earthRadius to a number before calling the distance method.