import { NominatimReverseGeocodingResponse } from '../../types/Types';

export const fetchAddressFromCoordinates = async (
    lat: number,
    lon: number
): Promise<NominatimReverseGeocodingResponse | null> => {
    try {
        const response = await fetch(
            `https://nominatim.openstreetmap.org/reverse?lat=${lat}&lon=${lon}&format=json&addressdetails=1&accept-language=fa`
        );
        const data = await response.json();
        return data;
    } catch (error) {
        console.error('Error fetching address:', error);
        return null;
    }
};

