- 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
This library ships different modules for working with geographical positions. Currently these are: Point, Vector and PointList
Working with Points
var myPoint =latitude: 500104469longitude: 87194302payload: 'Stangenpyramide';
You can make greatCircle calculate a vector between points by using the
var myVector = myPoint
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.
var myPoint =latitude: 564564longitude: 2payload: 'Bad Point';console;// Will output false
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.
var myVector = myPoint anotherPoint;
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.
var myList = ;myList;myList;console;// Will output 2myList;myList;
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
desc, default is
To retrieve the contained points, the PointList implements iteration as well as a
var sortedPoints = myList;for let point of myListconsole;// Will output all contained points by their distance in reference to the point and sorting given// by a previous call to ```sortByDistanceTo```.