ng-haversine
ng-haversine is an AngularJS module that applies the Haversine formula to a pair of coordinates to calculate the distance between them.
How to
The first step is to download the ng-haversine script. You can do it cloning this repo:
$ git clone https://github.com/vermicida/ng-haversine.git
Or via NPM:
$ npm install ng-haversine
Once the library is downloaded, make sure you are referencing it in your index.html
, just after the AngularJS library reference:
You must inject the ng-haversine dependency within your module setter:
angular;
Now, you are ready to go. You will need two coordinates given in the format below:
var coord1 = "latitude": 404169473 "longitude": -37057172; var coord2 = "latitude": 404236942 "longitude": -37109793;
To calculate the distance between them, you must use the function distance()
from the service $haversine
:
var distance = $haversine;
IMPORTANT: The distance is given in meters.
License
Code released under the MIT license.