0.1.5 • Published 4 years ago

geolocation-coordinate v0.1.5

Weekly downloads
3
License
MIT
Repository
-
Last release
4 years ago

geolocation-coordinate NPM version

ES6 class to simplify formatting of Geolocation coordinates

Installation

# NPM
npm install geolocation-coordinate --save

# Yarn
yarn add geolocation-coordinate

Getting Started

Creating a Coordinate instance from the browser Geolocation API

import { Coordinate } from 'geolocation-coordinate';


navigator.geolocation.getCurrentPosition((position) => {
  let { latitude, longitude } = position.coords;

  let latCoord = new Coordinate(latitude, 'latitude');
  let lngCoord = new Coordinate(longitude, 'longitude');

  latCoord.degrees; // 59.2349887712
  latCoord.minutes; // 14.09932627200007
  latCoord.seconds; // 5.959576320004203
  latCoord.cardinalCoordinate; // "North"

  latCoord.toString('dd'); // "59.235° North"
  latCoord.toString('ddm'); // "59° 14.099' North"
  latCoord.toString('dms'); // "59° 14' 6" North"
});

Documentation

Coordinate Class

Properties

Property NameTypeDescription
degreesFloatDegrees as decimal
minutesFloatMinutes as decimal
secondsFloatSeconds as decimal
cardinalDirectionStringDirection (North, East, South, West)

Methods

toString([format])

Returns coordinate as a pretty string

Format options
ArgumentDescriptionExample
DefaultReturns string in decimal degrees59.235° North
'dd'Returns string in decimal degrees format59.235° North
'ddm'Returns string in degree decimal minute format59° 14.099' North
'dms'Returns string in degree minutes seconds59° 14' 6" North

License

MIT License Copyright (c) 2018 Joel Colucci