0

Assuming I have the following:

Point A (lat, lon) 33.95,-118.4333

Point B (lat, lon) 33.9461,-118.4431

I want to get the angle/direction the line is pointing to. How do I do this in Javascript?

Rolando
  • 58,640
  • 98
  • 266
  • 407
  • `SIN`, `COS`, `ATAN2` are all available natively in JS. This might be helpful regarding degrees and radians: http://stackoverflow.com/q/135909/218196 . – Felix Kling Feb 09 '17 at 22:37
  • Check [**this**](http://www.movable-type.co.uk/scripts/latlong.html)! It could be of some help! – ibrahim mahrir Feb 09 '17 at 22:44

1 Answers1

0

There's a npm package for that:

https://www.npmjs.com/package/geojson-tools#getDistance

and it's fairly easy to use:

const { getDistance } = require('geojson-tools')
var array = [
    [20, 30],
    [20.5, 29.5]
 ];

 getDistance(array, 4); // 76.3212 

Units are in meters i believe.

If you need the actual code to getDistance, you may look for it here: https://github.com/MovingGauteng/GeoJSON-Tools/blob/master/src/geojson-tools.js

Seth Malaki
  • 4,436
  • 23
  • 48