Skip to content
Snippets Groups Projects
Commit 7e138bfb authored by Alex Reisner's avatar Alex Reisner
Browse files

Merge branch 'cloudmade_lookup' of git://github.com/spoptchev/geocoder into pr/377

Conflicts:
	lib/geocoder/lookup.rb
parents d70664bb e75a3f5e
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,7 @@ module Geocoder
:mapquest,
:ovi,
:baidu,
:cloudmade,
:test
]
end
......
require 'geocoder/lookups/base'
require 'geocoder/results/cloudmade'
module Geocoder::Lookup
class Cloudmade < Base
def name
"Cloudmade"
end
def query_url(query)
"http://geocoding.cloudmade.com/#{configuration.api_key}/geocoding/v2/find.js?#{url_query_string(query)}"
end
def required_api_key_parts
["key"]
end
private
def results(query)
data = fetch_data(query)
(data && data['features']) || []
end
def query_url_params(query)
params = {
:query => query.sanitized_text,
:return_location => true,
:return_geometry => false
}.merge(super)
end
end
end
require 'geocoder/results/base'
module Geocoder::Result
class Cloudmade < Base
def coordinates
@data["centroid"]["coordinates"]
end
def street
@data["location"]["road"]
end
def city
@data["location"]["city"]
end
def state
@data["location"]["county"]
end
alias_method :state_code, :state
def country
@data["location"]["country"]
end
alias_method :country_code, :country
def postal_code
@data["location"]["postcode"]
end
def address
[street, city, state, postal_code, country].compact.reject{|s| s.length == 0 }.join(", ")
end
end
end
Forbidden request
{"found": 2, "bounds": [[40.74983, -73.99433], [40.75116, -73.99266]], "features": [{"id": 32891803,"centroid": {"type":"POINT","coordinates":[40.75111, -73.99345]},"bounds": [[40.74983, -73.99433], [40.75116, -73.99266]],"properties": {"osm_element": "way", "sport": "hockey;basketball;lacrosse", "name": "Madison Square Garden", "leisure": "stadium", "osm_id": "24801588"},"location": {"county": "New York", "country": "United States of America", "postcode": "10119", "road": "West 31st Street", "city": "New York"},"type": "Feature"},{"id": 12977552,"centroid": {"type":"POINT","coordinates":[40.75066, -73.99347]},"bounds": [[40.75066, -73.99347], [40.75066, -73.99347]],"properties": {"building": "yes", "osm_element": "node", "name": "Madison Square Garden Center", "addr:state": "NY", "osm_id": "368045579"},"location": {"county": "New York", "country": "United States of America", "postcode": "10119", "road": "West 33rd Street", "city": "New York"},"type": "Feature"}], "type": "FeatureCollection", "crs": {"type": "EPSG", "properties": {"code": 4326, "coordinate_order": [0, 1]}}}
{}
......@@ -70,7 +70,7 @@ class LookupTest < Test::Unit::TestCase
# keep test output clean: suppress timeout warning
orig = $VERBOSE; $VERBOSE = nil
#Geocoder::Lookup.all_services_except_test.each do |l|
[:bing, :yahoo, :yandex, :maxmind].each do |l|
[:bing, :yahoo, :yandex, :maxmind, :cloudmade].each do |l|
Geocoder.configure(:lookup => l)
set_api_key!(l)
assert_equal [], Geocoder.search("invalid key")
......
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