This repository is an OpenCage Data API client for JavaScript and node.
Signup for a free API Key.
The library uses dotenv on node runtime to configure OpenCage Data API key.
First install the library with npm
or yarn
:
$ npm i --save opencage-api-client
or
$ yarn add opencage-api-client
Create a .env
file with:
OCD_API_KEY=YOUR-OPENCAGE_DATA_API_KEY
Here is an example:
const opencage = require('opencage-api-client');
opencage
.geocode({ q: 'lyon' })
.then(data => {
console.log(JSON.stringify(data));
})
.catch(error => {
console.log('error', error.message);
});
The browser version is built over the node one, obviously without the dotenv feature.
The library is available with unkpg
CDN : https://unpkg.com/[email protected]/dist/opencage-api.min.js
1- include the library:
<script src="https://unpkg.com/[email protected]/dist/opencage-api.min.js"></script>
2- use it
opencage
.geocode({ q: 'lyon' })
.then(data => {
console.log(JSON.stringify(data));
})
.catch(error => {
console.log('error', error.message);
});
Parameter | Type | Optional? | Description |
---|---|---|---|
q | String | mandatory | the query string to be geocoded; a placename or lat+long. This must be URL encoded. |
key | String | optional | the key can be omitted when using a proxyURL and when using node with a dedicated environment variable |
proxyURL | String | optional | The proxy URL parameter (useful to hide your API key) |
- Fork or clone this repository
$ cd
into therepository
folder$ npm install
to install all the required dependencies from npm- lint and test using
$ npm test
- coverage
$ npm run coverage
- Build :
$ npm run build
Version | Date | Description |
---|---|---|
v0.3.0 |
28/08/2018 | adding readme documentation and upgrade dependencies |
v0.2.0 |
17/07/2018 | Allow a proxy URL to use instead of official API endpoint |
v0.1.1 |
21/06/2018 | Open Cage website URL has changed |
v0.1.0 |
04/03/2018 | first release |
Nb Using European Date Format 😄 Sorry 🇺🇸
Anyone and everyone is welcome to contribute.
Find a bug or want to request a new feature? Please let me know by submitting an issue.
Licensed under the MIT License
A copy of the license is available in the repository's LICENSE file.