From 234746b43d72d09a4254f3cded9ac87e2c31904d Mon Sep 17 00:00:00 2001
From: Christian Aust <christian.aust@software-consultant.net>
Date: Wed, 17 Oct 2012 16:12:56 +0200
Subject: [PATCH] Add support for ovi.com, aka. Nokia maps. No reverse
 geocoding so far

---
 lib/geocoder/lookup.rb      |  1 +
 lib/geocoder/lookups/ovi.rb | 27 ++++++++++++++++++++
 lib/geocoder/results/ovi.rb | 50 +++++++++++++++++++++++++++++++++++++
 3 files changed, 78 insertions(+)
 create mode 100644 lib/geocoder/lookups/ovi.rb
 create mode 100644 lib/geocoder/results/ovi.rb

diff --git a/lib/geocoder/lookup.rb b/lib/geocoder/lookup.rb
index 4e58888d..0eb1c859 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 00000000..cbfa9387
--- /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 00000000..1af8bb89
--- /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
-- 
GitLab