/geosuggest

suggest by name or find nearest by coordinates cities

Primary LanguageRustMIT LicenseMIT

geosuggest

Library/Service to suggest and to find nearest by coordinates cities

Live demo with sources

Main features:

  • library or service modes
  • build index by free gazetteer data from geonames.org
  • suggest city by name
  • find nearest city by coordinates
  • MaxMind GeoIP2(Lite) city database support
  • multi-language (based on configured index options)
  • simple REST http api
  • no external services used

Based on:

Library

Crate usage example

$ cargo run -p geosuggest-examples --release --bin simple

Service

Install from sources (preferred).

$ git clone https://github.com/estin/geosuggest.git
$ cd geosuggest
$ cargo build --release

Build index file

$ cargo run -p geosuggest-utils --bin geosuggest-build-index --release --features=cli,tracing -- \
    from-urls \
    --languages=ru,uk,be,zh,ja \
    --output=/tmp/geosuggest-index.bincode

Run

$ GEOSUGGEST__INDEX_FILE=/tmp/geosuggest-index.bincode \
    GEOSUGGEST__HOST=127.0.0.1 \
    GEOSUGGEST__PORT=8080 \
    GEOSUGGEST__URL_PATH_PREFIX="/" \
    cargo run -p geosuggest --bin geosuggest --release

Check

$ curl -s "http://127.0.0.1:8080/api/city/suggest?pattern=Voronezh&limit=1" | jq
{
  "items": [
    {
      "id": 472045,
      "name": "Voronezh",
      "country": {
        "id": 2017370,
        "code": "RU",
        "name": "Russia"
      },
      "admin_division": {
        "id": 472039,
        "code": "RU.86",
        "name": "Voronezj"
      },
      "admin2_division": null,
      "timezone": "Europe/Moscow",
      "latitude": 51.67204,
      "longitude": 39.1843,
      "population": 848752
    }
  ],
  "time": 24
}

See also demo Dockerfile

Test

$ cargo test --workspace --all-features

License

This project is licensed under