For location-based services, it is often useful to display a name for any location. This can be achieved by reverse geocoding. By making use of Open Street Map data this project makes it possible to retrieve a location name for any coordinate worldwide in different languages (currently English and German).
GET /location/<latitude>/<longitude>
This is an example response for the GET query on http://localhost:8080/location/52.51/13.40
:
{
"coordinate": {
"latitude": 52.5099983215332,
"longitude": 13.3999996185303
},
"de": "Mitte, Berlin",
"en": "Mitte, Berlin"
}
POST /location
(POST method due to body content). The body looks like the following:
{
"coordinates": [
{
"latitude": 51.796873,
"longitude": 8.434899
},
{
"latitude": 51.804507,
"longitude": 8.432158
}
]
}
This request will return a nullified coordiante object in the response due to multiple input coordinates.
- Swift 5.8 is used with Vapor 4.
- Postgres with PostGIS is used for data storage and queries.
- Redis is used as a caching layer to improve performance.
- A docker-compose file is placed in the root directory. See the docker section for further steps with docker.
The following data structure is needed in the table place_polygon
:
name
: Stringname:de
: Stringname:en
: Stringway
: Geometry - Polygonadmin_level
: Intway_area
: Double
Here are instructions to create this table from the Open Street Map data. So the data is not part of this project.
- Clone this repo.
- Change the secrets for the database password and change the password file paths in the docker-compose file.
- Add a PostgreSQL data volume to store the database data on disk if you want to speed up noninitial startups.
- Run
docker-compose up
. - Import the prepared data (see the previous step) into the PostgreSQL database.
The web server also exposes a health endpoint to check if the service is running. The endpoint is available under GET /health
and returns the response code 200
.
DB_HOST
DB_PORT
DB_USERNAME
DB_DATABASE
DB_PASSWORD_FILE
DB_PASSWORD
(only used ifDB_PASSWORD_FILE
is not set)REDIS_URL
for the redis server url
This project is available under the AGPL Version 3 license. See the LICENSE file for more info.
You can contribute to this project by submitting a detailed issue or by forking this project and sending a pull request. Contributions of any kind are very welcome :)