Negatory. Postpone Mission.

# npm

Need private packages and team management tools?Check out npm Teams »

## @kevinulrich/greatcircle

2.0.0 • Public • Published

# greatCircle

A JavaScript toolbox for working with geographical entities. Currently supports single points, calculating their distance and sorting them by distance. Ideas for future expansion:

• Calculating Bearing between points
• Taking into account differences in altitude
• Calculating sunrise and sunset at a given point in time for a geographical position

``````npm install @kevinulrich/greatcircle
``````

# Example usage

This library ships different modules for working with geographical positions. Currently these are: Point, Vector and PointList

## Working with Points

The point constructor accepts an options object, no options actually have to be given. Missing latitude or longitude will default to 0, missing payload will default to an empty object. The payload can be any valid JavaScript object, string or number for example.

You can make greatCircle calculate a vector between points by using the `getVectorFrom` or `getVectorTo` methods.

greatCircle will help you validate geographical positions. You can simply input your latitude and longitude and it will not only check for valid numbers but also if the given latitude or longitude is within -180 and 180 degrees.

## Working with Vectors

The vector constructor takes two arguments for a starting and an end point. These must be valid Point objects. The order of start and end is very important as a vector is directional. As of 2.0, the library is only able to calculate the distance of a vector so the order is not important right now, but will become so once bearing and other features come into play.

You can not easily calculate the length of the vector by getting the distance. `getDistance` will return a number in meters.

## Working with PointLists

A pointlist is an aggregate of multiple points and can be used to determine the closest or fartherst point from another or even sort all points by their distance to a given reference point.

To sort all points within the list by their distance to or from another point you can use the `sortByDistanceTo` method. It will accept two parameters: The reference point to be used and a sorting parameter which accepts `asc` or `desc`, default is `asc`;

To retrieve the contained points, the PointList implements iteration as well as a `toArray` method.

## Keywords

### Install

`npm i @kevinulrich/greatcircle`

2

2.0.0

MIT

16.1 kB

10

### Repository

github.com/kevinulrich/greatCircle