get-lat-long-queue
Version:
A node js redis package that creates a queue of requests and processes with FIFO principles, spacing requests, and retrieving lattitude and longitude data for a specified address from Nominatim API.
28 lines (21 loc) • 607 B
JavaScript
const axios = require('axios');
const geosearch = async (q, limit = '1') => {
const params = new URLSearchParams({
q,
limit,
format: 'json',
});
const ENDPOINT = `https://nominatim.openstreetmap.org/search?${params.toString()}`;
try {
const response = await axios.get(ENDPOINT);
const payload = response.data;
if (!payload || !payload.length) {
throw new Error(`No response for Address: ${q}`);
}
return payload;
} catch (error) {
console.error(`Error during geosearch for Address: ${q}`, error);
throw error;
}
};
module.exports = geosearch;