pluscodes
v2.6.0
Published
Library to encode and decode plus codes
Downloads
3,353
Maintainers
Readme
Overview
Implementation of plus codes in Javascript/Typescript. See a description with running code at Runkit.
Usage
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, [email protected]