npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

haversine-calculator

v1.0.3

Published

Module to calculate the distance between two points on a sphere.

Downloads

173

Readme

Haversine Calculator

This is a simple module to help you determine the great-circle distance between two points on a sphere given their longitudes and latitudes o a geojson file.

The formula

This uses the ‘haversine’ formula to calculate the great-circle distance between two points – that is, the shortest distance over the earth’s surface – giving an ‘as-the-crow-flies’ distance between the points (ignoring any hills they fly over, of course!).

Haversine: a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2) c

formula: c = 2 ⋅ atan2( √a, √(1−a) ) d = R ⋅ c

where φ is latitude, λ is longitude, R is earth’s radius (mean radius = 6,371km); The angles need to be in radians to pass to trig functions.

Installation

`$ npm install haversine-calculator

Usage of this module

haversine (start, end, options)

const haversineCalculator = require('haversine-calculator')

const start = {
  latitude: -23.754842,
  longitude: -46.676781
}

const end = {
  latitude: -23.549588,
  longitude: -46.693210
}

console.log(haversineCalculator(start, end))
console.log(haversineCalculator(start, end, {unit: 'meter'}))
console.log(haversineCalculator(start, end, {unit: 'mile'}))
console.log(haversineCalculator(start, end, {threshold: 1}))
console.log(haversineCalculator(start, end, {threshold: 1, unit: 'meter'}))
console.log(haversineCalculator(start, end, {threshold: 1, unit: 'mile'}))

The api

  • options.unit - Unit of measurement applied to result (default km, available km, mile, meter, nmi)
  • options.threshold - If passed, will result in library returning boolean value of whether or not the start and end points are within that supplied threshold. (default null)
  • options.format - The format of start and end coordinate arguments. See the table below for available values. (default null)

| Format | Example | ------------- |--------------------------| | undefined (default) | { latitude: -23.754842, longitude: -46.676781] } | [lat,lon] | [-23.754842, -46.676781] | [lon,lat] | [-23.754842, -46.676781] | {lat,lon} | { lat: -23.754842, lon: -46.676781] } | geojson | { type: 'Feature', geometry: { coordinates: [-23.754842, -46.676781] } }

MIT License