latitude-longitude
Find the distance between two coordinates, or the center coordinates of multiple.
Table of Contents
Install
npm:
npm i latitude-longitude
yarn:
yarn add latitude-longitude
Usage
The names of the functions have been changed to make them more user friendly. Instead of long winded function names, there is a simple latlng
object that can then call easily readable functions getCenter()
and getDistance()
.
New:
import latlng from "latitude-longitude"
latlng.getCenter([[40.739683, 73.985151], [40.730601, 74.000447], [40.742256, 74.006344], [40.691805, 73.908089]])
//=> { lat: 40.72609295152872, lng: 73.97499628519203, zoom: 11 }
latlng.getDistance([40.739683, 73.985151], [40.730601, 74.000447])
//=> 1.6373159082193258
Old (still working):
import { latLngCenter, latLngDistance } from "latitude-longitude"
latLngCenter([[40.739683, 73.985151], [40.730601, 74.000447], [40.742256, 74.006344], [40.691805, 73.908089]])
//=> { lat: 40.72609295152872, lng: 73.97499628519203, zoom: 11 }
latLngDistance([40.739683, 73.985151], [40.730601, 74.000447])
//=> 1.6373159082193258
Responses
getCenter()
An object will be returned with lat, lng and zoom keys.
Response: Object
Key | Type | Description |
---|---|---|
lat |
float |
The central latitude coordinate between all provided coordinates. |
lng |
float |
The central longitude coordinate between all provided coordinates. |
zoom |
int |
The zoom level required by google maps to fit all coordinates in display. |
Object:
{
"lat": 40.72609295152872,
"lng": 73.97499628519203,
"zoom": 11
}
getDistance()
An floating point will be returned with the distance between two points in kilometers.
Response:
float
License
MIT © 2022 Rory Dobson