Skip to content

Library for working with GeoPosition for TypeScript πŸŒŽπŸ›°

License

Notifications You must be signed in to change notification settings

0xF6/geo-position.ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

40 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

geo-position.ts 🌎

Library for working with GeoPosition fot TypeScript

Build Status Dependencies CodeCov npm

Install

yarn add geo-position.ts

Run test

yarn test or yarn test-nya and for reports yarn report-test

image

Usage

Create GeoPosition from coordinates

import { GeoPosition } from 'geo-position.ts';

/* ... */

new GeoPosition(71.317941, 55.691416);

71.317941 //-  Latitude  (Ξ»)
55.691416 //-  Longitude (Ο†)

Distance:

let xPoint = new GeoPosition(71.317941, 55.691416);
let yPoint = new GeoPosition(71.500873, 55.807184);

+xPoint.Distance(yPoint).toFixed(0) // -> 20844 meters

Zero check

new GeoPosition(0, 0).IsZero()         // -> true
new GeoPosition(71.317941, 55.691416)  // -> false
GeoPosition.Zero.IsZero()              // -> true

Validate Coordinates

GeoPosition.IsValidGpsCoordinate(71.317941, 55.691416) // true
GeoPosition.IsValidGpsCoordinate(271.317941, 255.691416) // false

Parse Coordinates

GeoPosition.GetGpsPosition("N71.317941", "E55.691416"); // -> [71.317941, 55.691416]
GeoPosition.GetGpsPosition("S71,317941", "W55,691416"); // -> [-71.317941, -55.691416]

Is Inside Area

(this area array coordinates)
image

let area = [
        new GeoPosition(71.51834193441157, 55.116358997070286),
        new GeoPosition(71.44676509856431, 54.92684483691404),
        new GeoPosition(71.33845776024275, 55.123225452148404),
        new GeoPosition(71.36701875276431, 55.43084263964841),
        new GeoPosition(71.45113719694054, 55.575038196289),
        new GeoPosition(71.5065763194486, 55.40749669238277),
        new GeoPosition(71.51834193441157, 55.116358997070286)
    ]

new GeoPosition(71.436275, 55.220661).IsInsideArea(area) // true
new GeoPosition(0, 0).IsInsideArea(area)                 // false

SectionCenterPosition

let pos = new GeoPosition(71.436706, 55.268108);
let pos2 = new GeoPosition(71.473202, 55.857764);

GeoPosition.SectionCenterPosition(pos, pos2) // GeoPosition(71.454954, 55.562936)

image

DistanceToSection

let start = new GeoPosition(71.436706, 55.268108);
let end = new GeoPosition(71.473202, 55.857764);
let point = new GeoPosition(71.504361, 55.511926);
GeoPosition.SectionCenterPosition(point, start, end) // 5807 meters