-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
31 lines (24 loc) · 766 Bytes
/
Copy pathindex.js
File metadata and controls
31 lines (24 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
* Copyright 2020 ScaleDynamics SAS. All rights reserved.
* Licensed under the MIT license.
*/
'use strict'
const axios = require('axios')
// Go to https://opencagedata.com/api to get an API key
const OPENCAGE_API_KEY = 'YOUR_API_KEY'
/**
* Get the address by reverse geocoding of coordinates
*
* @param {number} latitude
* @param {number} longitude
*/
const getPosition = async (latitude, longitude) => {
const coordinates = `${latitude},${longitude}`
const url = `https://api.opencagedata.com/geocode/v1/json?key=${OPENCAGE_API_KEY}&q=${encodeURIComponent(
coordinates
)}&pretty=1&no_annotations=1`
const { data } = await axios.get(url)
const position = data.results[0].formatted
return position
}
module.exports = { getPosition }