zeke / all-the-cities

🌆 All the 138,398 cities of the world with a population of at least 1000 inhabitants, in a big JSON array.
http://npm.im/all-the-cities
MIT License
281 stars 42 forks source link

How to do reverse geocode #10

Closed teknolojia closed 5 years ago

teknolojia commented 5 years ago

With the function below I get list of cities in a certain country which includes lon and lat.

module.exports.getAreas = function (country) {
    const citiesArray = cities.filter(city => {
        return city.country.match(country)
    });

    return _.sortBy(citiesArray, o => o.name)
};

I want a way to use lat and lon to guess the city from this lib. Something like this:

module.exports.findArea = function (lon, lat) {
    return ........
};

I know its not the purpose of the lab, Any advice on how I can do it?

zeke commented 5 years ago

Hi @teknolojia! I think modules like https://github.com/zeke/euclidean-distance or https://github.com/zeke/nearby-cities might work for you.

teknolojia commented 5 years ago

@zeke thanks.