Module: GeoClue::ReverseGeocoder
- Defined in:
- lib/geoclue/reverse_geocoder.rb
Class Method Summary collapse
Class Method Details
.geocode(coords) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/geoclue/reverse_geocoder.rb', line 6 def geocode(coords) url = URI::HTTPS.build( scheme: "https", host: "nominatim.openstreetmap.org", path: "/reverse", query: URI.encode_www_form( format: 'json', lat: coords['latitude'], lon: coords['longitude'] ) ) result = JSON.parse(Net::HTTP.get(url)) return {} if ! result.key?("address") addr = result["address"] addr["settlement"] = addr["city"] || addr["town"] || addr["village"] addr end |