geographic-math
v1.0.1
Published
A set of useful geo functions
Downloads
6
Readme
Geo Math
Install
$ npm install geographic-math
Functions
isIncluded(position, polygon)
returnstrue
if the target position is inside the polygon defined by an array of{ lat, lon }
getDistance(position1, position2)
returns distance in km between the positions
Usage
import { getDistance, isIncluded } from 'geographic-math';
const polygon = [
{"lat": 55.705429470455414, "lon": 37.621419873046754},
{"lat": 55.70077659231783, "lon": 37.6090602539062},
{"lat": 55.70930644415837, "lon": 37.5836543701171},
{"lat": 55.72015991493216, "lon": 37.554128613281215},
{"lat": 55.741470416597515, "lon": 37.53421589355463},
{"lat": 55.76509203888301, "lon": 37.53833576660153},
{"lat": 55.774768881457526, "lon": 37.55412861328109},
{"lat": 55.79179426544748, "lon": 37.57404133300736},
{"lat": 55.79372849670679, "lon": 37.65163227539058},
{"lat": 55.779412909511215, "lon": 37.67017170410151},
{"lat": 55.77747796540244, "lon": 37.679784741210824},
{"lat": 55.76702760045296, "lon": 37.69214436035153},
{"lat": 55.74611842820403, "lon": 37.70038410644526},
{"lat": 55.71977234312517, "lon": 37.7072505615234},
{"lat": 55.709306444108734, "lon": 37.66673847656241},
{"lat": 55.70349083865831, "lon": 37.65506550292964}
];
isInside({"lat":55.72907299961868,"lon":37.614210095214084}, polygon); // true
isInside({"lat":55.79198769178762,"lon":37.677038159178}, polygon); // false
getDistance({"lat":55.79198769178762,"lon":37.677038159178}, {"lat":55.72907299961868,"lon":37.614210095214084}); // 8