Skip to content

Commit

Permalink
update distance docs (#2032)
Browse files Browse the repository at this point in the history
Co-authored-by: mfedderly <[email protected]>
  • Loading branch information
rowanwins and mfedderly authored Feb 14, 2021
1 parent a079713 commit f207991
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/turf-distance/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { getCoord } from "@turf/invariant";
import { radiansToLength, degreesToRadians, Coord, Units } from "@turf/helpers";
import {
radiansToLength,
degreesToRadians,
Coord,
Units,
Point,
} from "@turf/helpers";

//http://en.wikipedia.org/wiki/Haversine_formula
//http://www.movable-type.co.uk/scripts/latlong.html
Expand All @@ -9,8 +15,8 @@ import { radiansToLength, degreesToRadians, Coord, Units } from "@turf/helpers";
* This uses the [Haversine formula](http://en.wikipedia.org/wiki/Haversine_formula) to account for global curvature.
*
* @name distance
* @param {Coord} from origin point
* @param {Coord} to destination point
* @param {Coord | Point} from origin point or coordinate
* @param {Coord | Point} to destination point or coordinate
* @param {Object} [options={}] Optional parameters
* @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers
* @returns {number} distance between the two points
Expand All @@ -27,8 +33,8 @@ import { radiansToLength, degreesToRadians, Coord, Units } from "@turf/helpers";
* to.properties.distance = distance;
*/
function distance(
from: Coord,
to: Coord,
from: Coord | Point,
to: Coord | Point,
options: {
units?: Units;
} = {}
Expand Down

1 comment on commit f207991

@apt-exploit
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Distance calculation problem

I am trying to get the distance of these two coordinates. First I convert the DMS to DD coordinates, then I use toFixed to only use 3 decimal places. When executed, the answer is 340.360, but the correct answer is 340.871, a difference of 0.511 thousandths.

Means:

Calculation correctly: http://boulter.com/gps/distance

Written code

written-code

Correct answer

correct-answer

Please sign in to comment.