Skip to content
Snippets Groups Projects
Commit bcb0ea04 authored by Francesco Vollero's avatar Francesco Vollero
Browse files

Added mapquest open api

parent 5d4cb6b0
No related branches found
No related tags found
No related merge requests found
......@@ -57,7 +57,7 @@ module Geocoder
# All street address lookups, default first.
#
def street_lookups
[:google, :google_premier, :yahoo, :bing, :geocoder_ca, :yandex, :nominatim]
[:google, :google_premier, :yahoo, :bing, :geocoder_ca, :yandex, :nominatim,:mapquest]
end
##
......
require 'geocoder/lookups/base'
require "geocoder/results/mapquest"
module Geocoder::Lookup
class Mapquest < Base
def map_link_url(coordinates)
"http://www.openstreetmap.org/?lat=#{coordinates[0]}&lon=#{coordinates[1]}&zoom=15&layers=M"
end
private # ---------------------------------------------------------------
def results(query, reverse = false)
return [] unless doc = fetch_data(query, reverse)
doc.is_a?(Array) ? doc : [doc]
end
def query_url(query, reverse = false)
params = {
:format => "json",
:json_callback=>"?",
:polygon => "1",
:addressdetails => "1",
:"accept-language" => Geocoder::Configuration.language
}
if (reverse)
method = 'reverse'
parts = query.split(/\s*,\s*/);
params[:lat] = parts[0]
params[:lon] = parts[1]
else
method = 'search'
params[:q] = query
end
"http://open.mapquestapi.com/#{method}?" + hash_to_query(params)
end
end
end
require 'geocoder/results/base'
module Geocoder::Result
class Mapquest < Base
def house_number
@data['address']['house_number']
end
def address
@data['display_name']
end
def street
@data['address']['road']
end
def city
@data['address']['city']
end
def village
@data['address']['villiage']
end
def town
@data['address']['town']
end
def state
@data['address']['state']
end
alias_method :state_code, :state
def postal_code
@data['address']['postcode']
end
def county
@data['address']['county']
end
def country
@data['address']['country']
end
def country_code
@data['address']['country_code']
end
def coordinates
[@data['lat'].to_f, @data['lon'].to_f]
end
def self.response_attributes
%w[place_id, boundingbox, license,
polygonpoints, display_name, class, type, stadium, suburb]
end
response_attributes.each do |a|
define_method a do
@data[a]
end
end
end
end
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