20 lines
518 B
TypeScript
20 lines
518 B
TypeScript
import axios from 'axios';
|
|
const dotenv = require('dotenv');
|
|
|
|
dotenv.config();
|
|
|
|
const GEOCODING_API_KEY = process.env.GEOCODING_API_KEY;
|
|
|
|
export interface Address {
|
|
street: string;
|
|
line1: string;
|
|
line2: string;
|
|
country: string;
|
|
postcode: string;
|
|
}
|
|
|
|
export const resolveAddress = async (searchTerm: string): Promise<Address> => {
|
|
const response = await axios.get(`https://api.geoapify.com/v1/geocode/search?text=${searchTerm}&apiKey=${GEOCODING_API_KEY}`);
|
|
return response.data.features[0].properties;
|
|
};
|