# coordinate-parser

> Geographical coordinate parser

Latest version **1.0.7** (published 2020-09-27) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install coordinate-parser
pnpm add coordinate-parser
yarn add coordinate-parser
bun add coordinate-parser
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2020-09-27 |
| First published | 2015-11-06 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 22.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 39 |
| Author | WEPROG/otto-dev |
| Maintainers | otto-dev |

## Links

- npm: https://www.npmjs.com/package/coordinate-parser
- Repository: https://github.com/otto-dev/coordinate-parser
- Homepage: https://github.com/otto-dev/coordinate-parser#readme
- Issues: https://github.com/otto-dev/coordinate-parser/issues
- npm.io page: https://npm.io/package/coordinate-parser

## Recent versions

- 1.0.7 (latest) — 2020-09-27
- 1.0.6 — 2020-09-27
- 1.0.5 — 2020-09-27
- 1.0.4 — 2020-09-19
- 1.0.3 — 2020-01-20
- 1.0.2 — 2016-01-13
- 1.0.1 — 2015-11-18
- 1.0.0 — 2015-11-06

## README

# Coordinate Parser
## *Intelligent geographical coordinate parser in JavaScript*
Flexible algorithm to parse strings containing various latitude/longitude formats.

### Usage
```js
Coordinates = require('coordinate-parser');

position = new Coordinates('40:7:22.8N 74:7:22.8W');

latitude = position.getLatitude(); // 40.123 ✓
longitude = position.getLongitude(); // -74.123 ✓
```

### Supported formats
- `40.123, -74.123`
- `40.123° N 74.123° W`
- `40° 7´ 22.8" N 74° 7´ 22.8" W`
- `40° 7.38’ , -74° 7.38’`
- `N40°7’22.8, W74°7’22.8"`
- `40°7’22.8"N, 74°7’22.8"W`
- `40 7 22.8, -74 7 22.8`
- `40.123 -74.123`
- `40.123°,-74.123°`
- `144442800, -266842800`
- `40.123N74.123W`
- `4007.38N7407.38W`
- `40°7’22.8"N, 74°7’22.8"W`
- `400722.8N740722.8W`
- `N 40 7.38    W 74 7.38`
- `40:7:23N,74:7:23W`
- `40:7:22.8N 74:7:22.8W`
- `40°7’23"N 74°7’23"W`
- `40°7’23" -74°7’23"`
- `40d 7’ 23" N 74d 7’ 23" W`
- `40.123N 74.123W`
- `40° 7.38, -74° 7.38`

... and others that follow a similar pattern.

Handles also the following "exotic" formats:

- `145505994.48, -268708007.88` (*geographical milliseconds*)
- `4025.0999N7438.4668W` (*DDMM.xxxx*)
- `402505.994N743828.008W` (*DDMMSS.xxxx*)

### Coordinate validation
Input that does not resemble valid coordinates will throw an error.

The parser will detect invalid formats such as `40.123N FOOBAR 74.123W` (invalid characters), `40.123W 74.123N` (latitude/longitude exchanged) and `40.12  12.34  74.12` (odd numbers).

Flexibility towards non-alphanumeric characters and whitespaces is maintained.

```js
isValidPosition = function(position) {
  var error;
  var isValid;
  try {
    isValid = true;
    new Coordinates(position);
    return isValid;
  } catch (error) {
    isValid = false;
    return isValid;
  }
};

isCoordinate = isValidPosition('40:7:22.8N 74:7:22.8W'); // true
isCoordinate = isValidPosition('40.123 FOOBAR! 74.123'); // false
```

### Licence
This software is licensed under the Apache 2 license:
http://www.apache.org/licenses/LICENSE-2.0

Copyright (C) 2016 [WEPROG GmbH](http://www.weprog.com/)

### Credit
Originally developed for [WEPROG](http://www.weprog.com/) who kindly gave permission to open-source this code.

---
_Source: https://npm.io/package/coordinate-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
