Module: MapTP::Parser::GeocodingResult
- Defined in:
- lib/maptp-service/parser/geocoding_result.rb
Overview
Parses the results of a geocoding response.
Constant Summary collapse
- @@hierachy_to_name =
A hashtable containing the descriptive values for the hierachy property of the response.
{ 1 => "country", 2 => "state", 3 => "county", 4 => "city", 5 => "district", 6 => "street", 7 => "address", 8 => "zip" }
Class Method Summary collapse
-
.to_hash(response) ⇒ Object
Parses the response to a hash and strips all unneccessary data.
Class Method Details
.to_hash(response) ⇒ Object
Parses the response to a hash and strips all unneccessary data
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/maptp-service/parser/geocoding_result.rb', line 24 def self.to_hash(response) resp = response.to_hash results = resp[:search_free_response][:map_search_response][:alternatives][:item] output = Hash.new output[:results] = Array.new # Return empty array if no results are returned return output unless results results.each do |result| stripped_result = Hash.new major_properties = result[:properties_major][:item] #minor_properties = result[:properties_minor][:item] address = Hash.new major_properties.each do |property| address[:name] = property[:value] if property[:key] == "Name" # only for POIs address[:street] = property[:value] if property[:key] == "Street" address[:district] = property[:value] if property[:key] == "District" address[:city] = property[:value] if property[:key] == "City" address[:zip] = property[:value] if property[:key] == "Zip" address[:state] = property[:value] if property[:key] == "Sta" address[:county] = property[:value] if (property[:key] == "Cty" || property[:key] == "County") address[:country] = property[:value] if (property[:key] == "Ctry" || property[:key] == "Country") end stripped_result[:address] = address stripped_result[:type] = @@hierachy_to_name[result[:hierarchy].to_i] stripped_result[:quality] = result[:quality].downcase stripped_result[:coordinate] = { :lat => result[:coordinate][:latitude].to_f / 60, :lng => result[:coordinate][:longitude].to_f / 60 } output[:results] << stripped_result end output end |