Sha256: ecdd711e9f7cacca91e2575b40fed0ea5df866bbe60625ccda303cb849a9ced7
Contents?: true
Size: 1.97 KB
Versions: 33
Compression:
Stored size: 1.97 KB
Contents
# frozen_string_literal: true module Decidim module Map module Provider module Geocoding # The geocoding utility class for the HERE geocoding service class Here < ::Decidim::Map::Geocoding # @see Decidim::Map::Geocoding#address def address(coordinates, options = {}) # Pass in a radius of 50 meters as an extra attribute for the HERE # API. Also sort the results by distance and pass a maxresults # attribute of 5. results = search(coordinates + [50], { params: { sortby: :distance, maxresults: 5 } }.merge(options)) return if results.empty? # Always prioritize house number results, even if they are not as # close as street level matches. hn_result = results.find do |r| r.data["MatchLevel"] == "houseNumber" end return hn_result.address if hn_result # Some of the matches that have "MatchLevel" == "street" do not even # contain the street name unless they also have the "Street" key in # the "MatchQuality" attribute defined. street_result = results.find do |r| r.data["MatchQuality"].has_key?("Street") end return street_result.address if street_result # Otherwise, sort the results based on their exact distances from # the given coordinates (default functionality). results.sort! do |result1, result2| dist1 = Geocoder::Calculations.distance_between( result1.coordinates, coordinates ) dist2 = Geocoder::Calculations.distance_between( result2.coordinates, coordinates ) dist1 <=> dist2 end results.first.address end end end end end end
Version data entries
33 entries across 33 versions & 1 rubygems