UNPKG

2 kBMarkdownView Raw
1# @turf/bearing
2
3<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
4
5## bearing
6
7Takes two [points][1] and finds the geographic bearing between them,
8i.e. the angle measured in degrees from the north line (0 degrees)
9
10**Parameters**
11
12- `start` **[Coord][2]** starting Point
13- `end` **[Coord][2]** ending Point
14- `options` **[Object][3]** Optional parameters (optional, default `{}`)
15 - `options.final` **[boolean][4]** calculates the final bearing if true (optional, default `false`)
16
17**Examples**
18
19```javascript
20var point1 = turf.point([-75.343, 39.984]);
21var point2 = turf.point([-75.534, 39.123]);
22
23var bearing = turf.bearing(point1, point2);
24
25//addToMap
26var addToMap = [point1, point2]
27point1.properties['marker-color'] = '#f00'
28point2.properties['marker-color'] = '#0f0'
29point1.properties.bearing = bearing
30```
31
32Returns **[number][5]** bearing in decimal degrees, between -180 and 180 degrees (positive clockwise)
33
34[1]: https://tools.ietf.org/html/rfc7946#section-3.1.2
35
36[2]: https://tools.ietf.org/html/rfc7946#section-3.1.1
37
38[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
39
40[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
41
42[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number
43
44<!-- This file is automatically generated. Please don't edit it directly:
45if you find an error, edit the source file (likely index.js), and re-run
46./scripts/generate-readmes in the turf project. -->
47
48---
49
50This module is part of the [Turfjs project](http://turfjs.org/), an open source
51module collection dedicated to geographic algorithms. It is maintained in the
52[Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
53PRs and issues.
54
55### Installation
56
57Install this module individually:
58
59```sh
60$ npm install @turf/bearing
61```
62
63Or install the Turf module that includes it as a function:
64
65```sh
66$ npm install @turf/turf
67```