https://github.com/dcousens/haversine-distance
Haversine formula in Javascript. In meters. Nothing more.
https://github.com/dcousens/haversine-distance
haversine javascript
Last synced: about 1 year ago
JSON representation
Haversine formula in Javascript. In meters. Nothing more.
- Host: GitHub
- URL: https://github.com/dcousens/haversine-distance
- Owner: dcousens
- License: mit
- Created: 2015-05-05T05:39:49.000Z (about 11 years ago)
- Default Branch: main
- Last Pushed: 2024-06-07T06:40:55.000Z (about 2 years ago)
- Last Synced: 2024-10-19T02:06:37.456Z (over 1 year ago)
- Topics: haversine, javascript
- Language: JavaScript
- Homepage:
- Size: 58.6 KB
- Stars: 75
- Watchers: 3
- Forks: 10
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
# haversine-distance
[](https://www.npmjs.org/package/haversine-distance)
[](https://github.com/feross/standard)
Haversine formula in Javascript, in meters, nothing else
## Example
### Import
```javascript
const haversine = require('haversine-distance')
// or
import haversine from 'haversine-distance'
```
### Usage
```javascript
const a = { latitude: 37.8136, longitude: 144.9631 }
const b = { latitude: 33.8650, longitude: 151.2094 }
console.log(haversine(a, b)) // 714504.18 (in meters)
```
Alternative forms such as `lat`, `lng` and `lon` work too, with mixed support:
```javascript
const a = { lat: 37.8136, lng: 144.9631 }
const b = { lat: 33.8650, lon: 151.2094 }
console.log(haversine(a, b)) // 714504.18 (in meters)
```
### GeoJSON support
```javascript
const a = [144.9631, 37.8136]
const b = [151.2094, 33.865]
console.log(haversine(a, b)) // 714504.18 (in meters)
```
## LICENSE [MIT](LICENSE)