Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rentberry/geocoder
https://github.com/rentberry/geocoder
geocoding go golang google-geocode-api grpc hacktoberfest opencage
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/rentberry/geocoder
- Owner: Rentberry
- License: gpl-3.0
- Created: 2020-06-04T13:53:32.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-03-06T23:16:13.000Z (over 1 year ago)
- Last Synced: 2024-10-13T06:21:45.953Z (about 1 month ago)
- Topics: geocoding, go, golang, google-geocode-api, grpc, hacktoberfest, opencage
- Language: Go
- Homepage:
- Size: 6.81 MB
- Stars: 6
- Watchers: 3
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gRPC based geocoding service
Adapter for external geocoding services with caching, monitoring, metrics etc. Has built-in support for timezone queries (resolve coordinates to timezone) implemented using [amazing Brad Fitzpatrick's library](https://github.com/bradfitz/latlong).
Supports [Google's Geocoding API](https://developers.google.com/maps/documentation/geocoding/start) and [Opencage](https://opencagedata.com) for now.# Usage
## Docker image
```
docker run \
-p 8080:8080 -p 9092:9092 \
-e REDIS_HOST=redis \
-e GOOGLE_API_KEY_SERVER= \
-e OPENCAGE_API_KEY= \
rentberry:geocoder
```
This will start geocoding service that listens for grpc connections
on port `8080` and exposes prometheus metrics on `/metrics` on port `9092`## gRPC methods
### Geocoding
Forward and reverse geocoding
```GeocodeService.Geocode (LocationRequest) returns (LocationResponse)```
#### Example
Request:
```json5
// Forward
{
"address": "berlin",
"provider": "opencage",
"query": {
"country": "de",
"language": "en"
}
}// Reverse
{
"latLng": {"lat":52.51006317138672, "lng":13.40505599975586},
"provider": "opencage",
"query": {
"language": "en"
}
}
```
Response:
```json5
{
"locations": [
{
"provider": "opencage",
"formattedAddress": "Best Western Hotel am Spittelmarkt, Neue Grünstraße 28, 10179 Berlin, Germany",
"country": {
"name": "Germany",
"code": "DE"
},
"streetNumber": "28",
"streetName": "Neue Grünstraße",
"locality": "Berlin",
"sublocality": "Spandauer Vorstadt",
"postalCode": "10179",
"latLng": {
"lat": 52.51006317138672,
"lng": 13.40505599975586
},
"adminLevels": [
{
"level": 1,
"name": "Berlin",
"code": "BE"
}
],
"state": {
"name": "Berlin",
"code": "BE"
},
"bounds": {
"northEast": {
"lat": 52.510196685791016,
"lng": 13.405620574951172
},
"southWest": {
"lat": 52.50993347167969,
"lng": 13.40455150604248
}
}
},
{
"provider": "opencage",
"formattedAddress": "Neue Grünstraße 28, 10179 Berlin, Germany",
"country": {
"name": "Germany",
"code": "DE"
},
"streetNumber": "28",
"streetName": "Neue Grünstraße",
"locality": "Berlin",
"sublocality": "Spandauer Vorstadt",
"postalCode": "10179",
"latLng": {
"lat": 52.5099983215332,
"lng": 13.40558910369873
},
"adminLevels": [
{
"level": 1,
"name": "Berlin",
"code": "BE"
}
],
"state": {
"name": "Berlin",
"code": "BE"
},
"bounds": {
"northEast": {
"lat": 52.510047912597656,
"lng": 13.405638694763184
},
"southWest": {
"lat": 52.50994873046875,
"lng": 13.405538558959961
}
}
},
{
"provider": "opencage",
"formattedAddress": "10179, Germany",
"country": {
"name": "Germany",
"code": "DE"
},
"postalCode": "10179",
"latLng": {
"lat": 52.51359939575195,
"lng": 13.423199653625488
},
"state": {},
"bounds": {
"northEast": {},
"southWest": {}
}
}
],
"exists": true
}// Response trailers received:
// cache-key: b6d1655e0fc8945a33b050c4dfdb43b2cb0ecf58
```### Timezone lookup
Find location's timezone by provided coordinates
````TimezoneService.Lookup (TimezoneRequest) returns (Timezone)````
#### Example
Request:
```shell script
grpcurl -plaintext -import-path ./api -proto geocoder.proto -v -d '{"latLng":{"lat":52.51006317138672, "lng":13.40505599975586}}' 127.0.0.1:8080 geocoder.TimezoneService/Lookup
```
```json5
{"latlng": {"lat":52.51006317138672, "lng":13.40505599975586}}
```
Response:
```json5
{
"code": "Europe/Berlin"
}
```