Skip to content
Snippets Groups Projects
Commit 509ab4f3 authored by Rob Murray's avatar Rob Murray
Browse files

Add minimal PostcodeAnywhere UK geocoding provider

parent 01c98dfd
No related branches found
No related tags found
No related merge requests found
require 'geocoder/lookups/base'
require 'geocoder/results/postcode_anywhere_uk'
module Geocoder::Lookup
class PostcodeAnywhereUk < Base
BASE_URL_GEOCODE_V200 = 'services.postcodeanywhere.co.uk/Geocoding/UK/Geocode/v2.00/json.ws'
def name
'PostcodeAnywhereUk'
end
def required_api_key_parts
%w(key)
end
def query_url(query)
format('%s://%s?%s', protocol, BASE_URL_GEOCODE_V200, url_query_string(query))
end
private
def results(query)
response = fetch_data(query)
return [] if response.nil? || !response.is_a?(Array) || response.empty?
return response
end
def query_url_params(query)
{
:location => query.sanitized_text,
:key => configuration.api_key
}.merge(super)
end
end
end
require 'geocoder/results/base'
module Geocoder::Result
class PostcodeAnywhereUk < Base
def coordinates
[@data['Latitude'].to_f, @data['Longitude'].to_f]
end
def blank_result
''
end
alias_method :state, :blank_result
alias_method :state_code, :blank_result
alias_method :postal_code, :blank_result
def country
'United Kingdom'
end
def country_code
'UK'
end
def address
[@data['Location'], @data['OsGrid']].join(', ')
end
end
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment