Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/js-pugilist/geolocation-promise
https://github.com/js-pugilist/geolocation-promise
geolocation promise
Last synced: 10 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/js-pugilist/geolocation-promise
- Owner: js-pugilist
- Created: 2020-05-22T07:14:16.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-05-23T12:57:04.000Z (over 4 years ago)
- Last Synced: 2024-10-05T00:13:13.648Z (about 1 month ago)
- Topics: geolocation, promise
- Language: JavaScript
- Homepage: https://geolocation-promise.js.org/
- Size: 3.91 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# Geolocation-promise
Too many we find ourselves unable to use javascript's geolocation API as promise. This package fixes that, geolocation's **`getCurrentPosition`**
is implemented using promise and user can use function : **`getCurrentPositionPromise`** which returns a promise.# Installation
npm i geolocation-promise
> requires browser environment as it uses **navigator**
# Usage
## getCurrentPositionPromiseconst { getCurrentPositionPromise } = require('geolocation-promise');
getCurrentPositionPromise()
.then((position) => {
console.log(position);
})
.catch(e => console.log(e));
OR use async/awaitconst { getCurrentPositionPromise } = require('geolocation-promise');
//inside async function
try{
const position = await getCurrentPositionPromise();
console.log(position);
}catch(e){
console.log(e);
}> Incase of error promise gets rejected with an object like this:
{ error: ERROR_INFORMATION_STRING }
# Parameters
While using getCurrentPositionPromise() user can pass option object in the function.const options = {
enableHighAccuracy: false,//default
timeout: 5000,//default (milliseconds)
maximumAge: 10000 //default (milliseconds)
}
# Suggestions/ Feedback
For any suggestions or feedback ping me on : [Abhishek Singh (Gmail)](mailto:[email protected])