MEASUREMENT
COORDINATE MUTATION
TRANSFORMATION
FEATURE_CONVERSION
MISC
HELPER
RANDOM
GRIDS
AGGREGATION
META
ASSERTIONS
BOOLEANS
UNIT CONVERSION
DATA
JOINS
CLASSIFICATION

bearing

The bearing module of Turf provides functions for measuring the bearing or direction between two points on a sphere or a flat surface, expressed as an angle from north.

API

turf.bearing(point1, point2, options?)

Calculates the bearing or direction from point1 to point2 in degrees (angle from north).

Parameters

  • point1 (Array|Object): point coordinates as an array of longitude and latitude or an object with lng and lat properties.
  • point2 (Array|Object): point coordinates as an array of longitude and latitude or an object with lng and lat properties.
  • options (Object, optional):
    • final (Boolean, optional): if true, returns the final bearing instead of the initial bearing. Default is false.

Returns

  • bearing (Number): the bearing from point1 to point2 in degrees, from north.

turf.rhumbBearing(point1, point2, options?)

Calculates the bearing or direction from point1 to point2 along a rhumb line or a loxodrome, expressed as an angle from north.

Parameters

  • point1 (Array|Object): point coordinates as an array of longitude and latitude or an object with lng and lat properties.
  • point2 (Array|Object): point coordinates as an array of longitude and latitude or an object with lng and lat properties.
  • options (Object, optional):
    • final (Boolean, optional): if true, returns the final bearing instead of the initial bearing. Default is false.

Returns

  • bearing (Number): the bearing from point1 to point2 along a rhumb line or loxodrome in degrees, from north.

Example

var point1 = [-75.0, 45.0];
var point2 = [-74.0, 45.0];

var bearing = turf.bearing(point1, point2);
console.log(bearing); // output: 90

var rhumbBearing = turf.rhumbBearing(point1, point2);
console.log(rhumbBearing); // output: 90

Note

Both functions assume that the points are valid and within the range of acceptable values for longitude and latitude. The bearing function uses the spherical law of cosines to calculate the angle between two points on a sphere, while the rhumb bearing function uses the Mercator projection to calculate the angle between two points along a rhumb line or loxodrome.