pluscodes
TypeScript icon, indicating that this package has built-in type declarations

2.6.0 • Public • Published

Overview

Implementation of plus codes in Javascript/Typescript. See a description with running code at Runkit.

Usage

Diagram

Encoding

const { encode } = require('pluscodes')
encode({ latitude: 59.332438, longitude: 18.118813 }) // '9FFW84J9+XG'
encode({ latitude: 59.332438, longitude: 18.118813 }, 8) // '9FFW84J9+'
encode({ latitude: 59.332438, longitude: 18.118813 }, 4) // '9FFW0000+'

Decoding

const { decode } = require('pluscodes')
decode('9FFW84J9+XG') // { latitude: 59.332438, longitude: 18.118813, resolution: 0.000125 }
decode('9FFW84J9+') // { latitude: 59.331250, longitude: 18.118750, resolution: 0.0025 }
decode('9FFW0000+') // { latitude: 59.500000, longitude: 18.500000, resolution: 1 }

Shortening codes

const { shorten } = require('pluscodes')
shorten('9FFW84J9+XG', { latitude: 59.329394, longitude: -162.068712 }) // '9FFW84J9+XG'
shorten('9FFW84J9+XG', { latitude: 59.329394, longitude: 18.068712 }) // '84J9+XG'
shorten('9FFW84J9+XG', { latitude: 59.332438, longitude: 18.118813 }) // 'J9+XG'

Expanding short codes

const { expand } = require('pluscodes')
expand('FW84J9+XG', { latitude: 59.329394, longitude: 18.068712 }) // '9FFW84J9+XG'
expand('84J9+XG', { latitude: 59.329394, longitude: 18.068712 }) // '9FFW84J9+XG'
expand('J9+XG', { latitude: 59.329394, longitude: 18.068712 }) // '9FFW83J9+XG'

Author

Jan Andersson, jan.andersson@gmail.com

Package Sidebar

Install

npm i pluscodes

Weekly Downloads

651

Version

2.6.0

License

MIT

Unpacked Size

43.1 kB

Total Files

39

Last publish

Collaborators

  • jan_andersson