https://github.com/joelcolucci/geolocation-coordinate
ES6 class to simplify formatting of Geolocation coordinates
https://github.com/joelcolucci/geolocation-coordinate
coordinates dms format geolocation latitude longitude
Last synced: about 1 month ago
JSON representation
ES6 class to simplify formatting of Geolocation coordinates
- Host: GitHub
- URL: https://github.com/joelcolucci/geolocation-coordinate
- Owner: joelcolucci
- License: mit
- Created: 2018-08-13T15:37:41.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T14:47:28.000Z (over 3 years ago)
- Last Synced: 2025-02-16T05:46:56.448Z (over 1 year ago)
- Topics: coordinates, dms, format, geolocation, latitude, longitude
- Language: JavaScript
- Size: 1.2 MB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# geolocation-coordinate [](https://www.npmjs.com/package/geolocation-coordinate)
> 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
```javascript
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 Name | Type | Description |
| ------------- | ---- | ----------- |
| degrees | Float | Degrees as decimal |
| minutes | Float | Minutes as decimal |
| seconds | Float | Seconds as decimal |
| cardinalDirection | String | Direction (North, East, South, West) |
#### Methods
`toString([format])`
Returns coordinate as a pretty string
##### Format options
| Argument | Description | Example|
| ------- | ----- | ----------- |
| Default| Returns string in decimal degrees | 59.235° North |
| 'dd' | Returns string in decimal degrees format | 59.235° North|
| 'ddm' | Returns string in degree decimal minute format | 59° 14.099' North |
| 'dms' | Returns string in degree minutes seconds | 59° 14' 6" North|
## License
MIT License Copyright (c) 2018 Joel Colucci