Skip to content

Commit

Permalink
Merge branch 'add-ovi' of git://github.com/datenimperator/geocoder in…
Browse files Browse the repository at this point in the history
…to datenimperator-add-ovi

Conflicts:
	test/test_helper.rb
  • Loading branch information
alexreisner committed Feb 9, 2013
2 parents f9e1ade + 5437240 commit 435d038
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,17 @@ Yahoo BOSS is **not a free service**. As of November 17, 2012 Yahoo no longer of
* **Terms of Service**: http://info.mapquest.com/terms-of-use/
* **Limitations**: ?

#### ovi.com (Nokia maps) (`:ovi`)

* **API key**: required: `config.api_key = %w{app_id app_token}`
* **Quota**: ?
* **Region**: world
* **SSL support**: no
* **Languages**: English
* **Documentation**: ?
* **Terms of Service**: ?
* **Limitations**: ?

#### FreeGeoIP (`:freegeoip`)

* **API key**: none
Expand Down
1 change: 1 addition & 0 deletions lib/geocoder/lookup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def street_services
:yandex,
:nominatim,
:mapquest,
:ovi,
:test
]
end
Expand Down
46 changes: 46 additions & 0 deletions lib/geocoder/lookups/ovi.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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']
if r=doc['Response']['View']
return [] if r.nil? || !r.is_a?(Array) || r.empty?
return r.first['Result']
end
[]
end

def query_url_params(query)
super.merge(
:searchtext=>query.sanitized_text,
:gen=>1,
:app_id=>api_key,
:app_code=>api_code
)
end

def api_key
if a=Geocoder::Configuration.api_key
return a.first if a.is_a?(Array)
end
end

def api_code
if a=Geocoder::Configuration.api_key
return a.last if a.is_a?(Array)
end
end

def query_url(query)
"http://lbs.ovi.com/search/6.2/geocode.json?" + url_query_string(query)
end
end
end
64 changes: 64 additions & 0 deletions lib/geocoder/results/ovi.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
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['County']
end

def province
fail unless d = @data['Location']['Address']
d['County']
end

def postal_code
fail unless d = @data['Location']['Address']
d['PostalCode']
end

def city
fail unless d = @data['Location']['Address']
d['City']
end

def state_code
fail unless d = @data['Location']['Address']
d['State']
end

def province_code
fail unless d = @data['Location']['Address']
d['State']
end

def country
fail unless d = @data['Location']['Address']['AdditionalData']
if v = d.find{|ad| ad['key']=='CountryName'}
return v['value']
end
end

def country_code
fail unless d = @data['Location']['Address']
d['Country']
end
end
end
72 changes: 72 additions & 0 deletions test/fixtures/ovi_madison_square_garden.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"Response": {
"MetaInfo": {
"Timestamp": "2013-02-08T16:26:39.382+0000"
},
"View": [
{
"_type": "SearchResultsViewType",
"ViewId": 0,
"Result": [
{
"Relevance": 1.0,
"MatchLevel": "houseNumber",
"MatchQuality": {
"State": 1.0,
"City": 1.0,
"Street": [
1.0
],
"HouseNumber": 1.0
},
"MatchType": "pointAddress",
"Location": {
"LocationId": "NT_ArsGdYbpo6dqjPQel9gTID_4",
"LocationType": "point",
"DisplayPosition": {
"Latitude": 40.7504692,
"Longitude": -73.9933777
},
"NavigationPosition": [
{
"Latitude": 40.7500305,
"Longitude": -73.9942398
}
],
"MapView": {
"TopLeft": {
"Latitude": 40.7515934,
"Longitude": -73.9948616
},
"BottomRight": {
"Latitude": 40.7493451,
"Longitude": -73.9918938
}
},
"Address": {
"Label": "4 Penn Plz, New York, NY 10001, United States",
"Country": "USA",
"State": "NY",
"County": "New York",
"City": "New York",
"Street": "Penn Plz",
"HouseNumber": "4",
"PostalCode": "10001",
"AdditionalData": [
{
"value": "United States",
"key": "CountryName"
},
{
"value": "New York",
"key": "StateName"
}
]
}
}
}
]
}
]
}
}
8 changes: 8 additions & 0 deletions test/fixtures/ovi_no_results.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Response": {
"MetaInfo": {
"Timestamp": "2013-02-08T16:41:16.723+0000"
},
"View": []
}
}

0 comments on commit 435d038

Please sign in to comment.