Coder Social home page Coder Social logo

haversort's Introduction

haversort

An implementation of a haversine algorhythm for finding the distance, in KM, between two latitudes and longtudes on Earth.

Usage

npm install -S haversort

> var h = require('haversort');
> h.distanceSort(10, 10, [[18,18], [12,12], [13,13], [14,14]]);
[ [ 12, 12, 312 ],
  [ 13, 13, 467.5 ],
  [ 14, 14, 622.8 ],
  [ 18, 18, 1240.3 ] ]
> h.haversine(10, 10, 20, 20);
1546.5

API

distanceSort(lat, lon, points) → {array}

Given a point and a list of points, returns the list sorted by distance (closest first)

Parameters:
Name Type Description
lat mixed

Lat of center point or array of [lat, lon] representing the center point

lon mixed

Lon of center point or array of points to sort

points array

Array of points to sort

Source:
Returns:

Array of points, sorted by distance from center point, with the distance pushed as the last element in each array

Type
array

haversine(lat1, lon1, lat2, lon2) → {number}

Compute the distance between two points using the haversine formula, based on the above defined Radius.

Parameters:
Name Type Argument Description
lat1 mixed

First lat, or an array of [lat, lon] representing the first point

lon1 mixed

First lon, or an array of [lat, lon] resresenting the second point

lat2 number <optional>

The latitude of the second point

lon2 number <optional>

The longitude of the second point

Source:
Returns:

The distance, in KM, between the two points, rounded to the tenths.

Type
number

toRad(num) → {number}

Give that trig function a radian. Trig functions LOVE radians

Parameters:
Name Type Description
num number

Angle, in degrees to return as a Radian

Source:
Returns:

The radian for that angle.

Type
number

generated with docme

##License & Copyright Copyright (c) 2014 Todd Kennedy, licensed under the MIT License

haversort's People

Contributors

toddself avatar

Stargazers

Cat  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.