Geo Coordinate Parser
A Javascript function for reading a variety of coordinate formats and converting to decimal numbers. Builds on other efforts for convenience by returning the verbatim coordinates and the decimal coordinates all in one object. Also includes a function to test existing decimal coordinates against those from the converter.
Usage
const convert = require('geo-coordinate-parser');
let converted = convert('40° 26.7717, -79° 56.93172');
converted.decimalLatitude;
converted.decimalLongitude;
converted.verbatimLatitude;
converted.verbatimLongitude;
The returned object includes properties verbatimCoordinates, verbatimLatitude, verbatimLongitude, decimalLatitude, decimalLatitude, and decimalCoordinates.
Sometimes we may want to validate existing decimal coordinates against those returned from the converter to find errors. Because we're working with decimal numbers we must settle for values that are close enough (in this case the same up to six decimal places).
converted.closeEnough(yourDecimalCoordinatesToTest)
Supported formats
All formats (except the 'exotic formats') covered by npm coordinate-parser and the coordinate regex in this GitHub Gist, as well as the following:
- -23.3245° S / 28.2344° E
- 27deg 15min 45.2sec S 18deg 32min 53.7sec E
- 40° 26.7717 -79° 56.93172
- 18.24S 22.45E // read as degrees and minutes
Formats used to testing can be be accessed with:
covert.formats
Note to users: Please add coordinate formats that throw an error in the Github Issues.
License
MIT Licence
Acknowledgements
Support for development was provided by the Animal Demography Unit of the University of Cape Town.