diff --git a/lib/geocoder/lookup.rb b/lib/geocoder/lookup.rb index 4e58888d09ab9f46a4e5287883a4a23075f92e4e..0eb1c85959541071e02aa634567dcc81eaecfa65 100644 --- a/lib/geocoder/lookup.rb +++ b/lib/geocoder/lookup.rb @@ -29,6 +29,7 @@ module Geocoder :yandex, :nominatim, :mapquest, + :ovi, :test ] end diff --git a/lib/geocoder/lookups/ovi.rb b/lib/geocoder/lookups/ovi.rb new file mode 100644 index 0000000000000000000000000000000000000000..cbfa9387a475569a714207cc1639f4b7e509345a --- /dev/null +++ b/lib/geocoder/lookups/ovi.rb @@ -0,0 +1,27 @@ +# ovi.com store + +require 'geocoder/lookups/base' +require "geocoder/results/ovi" + +module Geocoder::Lookup + class Ovi < Base + + private # --------------------------------------------------------------- + + def results(query) + return [] unless doc = fetch_data(query) + return [] unless doc['Response'] + doc['Response']['View'].first['Result'] + end + + def query_url_params(query) + { + :searchtext => query.sanitized_text + } + end + + def query_url(query) + "http://lbs.ovi.com/search/6.2/geocode.json?" + url_query_string(query) + end + end +end diff --git a/lib/geocoder/results/ovi.rb b/lib/geocoder/results/ovi.rb new file mode 100644 index 0000000000000000000000000000000000000000..1af8bb89bae9bd02ffd0f205fa13d1e9aa179180 --- /dev/null +++ b/lib/geocoder/results/ovi.rb @@ -0,0 +1,50 @@ +require 'geocoder/results/base' + +module Geocoder::Result + class Ovi < Base + + ## + # A string in the given format. + # + def address(format = :full) + fail unless d = @data['Location']['Address'] + d['Label'] + end + + ## + # A two-element array: [lat, lon]. + # + def coordinates + fail unless d = @data['Location']['DisplayPosition'] + [d['Latitude'].to_f, d['Longitude'].to_f] + end + + def state + fail unless d = @data['Location']['Address'] + d['State'] + end + + def province + fail unless d = @data['Location']['Address'] + d['County'] + end + + def state_code + fail + end + + def province_code + fail + end + + def country + fail unless d = @data['Location']['Address']['AdditionalData'] + d.find{|ad| ad['value'] if ad['key']=='CountryName'} + end + + def country_code + fail unless d = @data['Location']['Address'] + d['Country'] + end + end +end