UNPKG

city

Version:

The City API returns the city from a latitude and longitude using spatial mapping and data anlysis.

30 lines (26 loc) 906 B
const axios = require('axios') const api = 'https://city-grabber.herokuapp.com/api/v1' module.exports = { /** * This will return the City and Country from GPS coordinates * @param {Number} latitude The latitude value * @param {Number} longitude The longitude value * @param {Number | Null} size The city size value * @param {String} apiKey The API key * @return {Object} */ get: async( latitude, longitude, size = null, apiKey ) => { const route = '/cities/nearest' let url = api + route + '?latitude=' + latitude + '&longitude=' + longitude if ( size !== null ) url += '&size=' + size const headers = {} if ( apiKey ) headers[ 'x-api-key' ] = apiKey const response = await axios(url, { method: 'GET', headers }).catch( e => { return Promise.reject( e.response.data ) }) return Promise.resolve( response.data ) } }