UNPKG

1.88 kBMarkdownView Raw
1# @turf/bearing
2
3# bearing
4
5Takes two [points](http://geojson.org/geojson-spec.html#point) and finds the geographic bearing between them.
6
7**Parameters**
8
9- `start` **[Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)>** starting Point
10- `end` **[Feature](http://geojson.org/geojson-spec.html#feature-objects)<[Point](http://geojson.org/geojson-spec.html#point)>** ending Point
11- `final` **\[[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)]** calculates the final bearing if true (optional, default `false`)
12
13**Examples**
14
15```javascript
16var point1 = {
17 "type": "Feature",
18 "properties": {
19 "marker-color": '#f00'
20 },
21 "geometry": {
22 "type": "Point",
23 "coordinates": [-75.343, 39.984]
24 }
25};
26var point2 = {
27 "type": "Feature",
28 "properties": {
29 "marker-color": '#0f0'
30 },
31 "geometry": {
32 "type": "Point",
33 "coordinates": [-75.534, 39.123]
34 }
35};
36
37var bearing = turf.bearing(point1, point2);
38point1.properties.bearing = bearing
39//=bearing
40```
41
42Returns **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** bearing in decimal degrees
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```