1.1.1 • Published 2 years ago

latitude-longitude v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

latitude-longitude

npm npm

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

KeyTypeDescription
latfloatThe central latitude coordinate between all provided coordinates.
lngfloatThe central longitude coordinate between all provided coordinates.
zoomintThe 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