1 | # @turf/bearing
|
2 |
|
3 |
|
4 |
|
5 | ## bearing
|
6 |
|
7 | Takes two [points][1] and finds the geographic bearing between them,
|
8 | i.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
|
20 | var point1 = turf.point([-75.343, 39.984]);
|
21 | var point2 = turf.point([-75.534, 39.123]);
|
22 |
|
23 | var bearing = turf.bearing(point1, point2);
|
24 |
|
25 | //addToMap
|
26 | var addToMap = [point1, point2]
|
27 | point1.properties['marker-color'] = '#f00'
|
28 | point2.properties['marker-color'] = '#0f0'
|
29 | point1.properties.bearing = bearing
|
30 | ```
|
31 |
|
32 | Returns **[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 |
|
45 | if 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 |
|
50 | This module is part of the [Turfjs project](http://turfjs.org/), an open source
|
51 | module collection dedicated to geographic algorithms. It is maintained in the
|
52 | [Turfjs/turf](https://github.com/Turfjs/turf) repository, where you can create
|
53 | PRs and issues.
|
54 |
|
55 | ### Installation
|
56 |
|
57 | Install this module individually:
|
58 |
|
59 | ```sh
|
60 | $ npm install @turf/bearing
|
61 | ```
|
62 |
|
63 | Or install the Turf module that includes it as a function:
|
64 |
|
65 | ```sh
|
66 | $ npm install @turf/turf
|
67 | ```
|