0

I am using Node-Geocoder to find the lat and long of different cities.

type docs: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/node-geocoder/index.d.ts#L135

This is my code:

import NodeGeocoder from 'node-geocoder';

const Geocoder = async (city: string) => {
    const options: NodeGeocoder.Options = {
        provider: 'openstreetmap'
    };

    const query: NodeGeocoder.Query = {
        city: city,
        country: 'Colombia',
        limit: 1
    };

    const geocoder = NodeGeocoder(options);
    const data = await geocoder.geocode(query);
    const { latitude, longitude } = data[0];
    return { lat: latitude, lng: longitude };
};

export default Geocoder;

I know the interface Query does not accept a city property. Yet it still works when I enter a city name. If I try the same with the property "address," it does not give me the right coordinates. How can I pass a city name to the geocode?

0 Answers0