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

Add support for :bounds option to Google.

parent 482887bd
No related branches found
No related tags found
No related merge requests found
......@@ -284,6 +284,7 @@ Quota:: 2,500 requests/day, 100,000 with Google Maps API Premier
Region:: world
SSL support:: yes
Languages:: ar, eu, bg, bn, ca, cs, da, de, el, en, en-AU, en-GB, es, eu, fa, fi, fil, fr, gl, gu, hi, hr, hu, id, it, iw, ja, kn, ko, lt, lv, ml, mr, nl, no, pl, pt, pt-BR, pt-PT, ro, ru, sk, sl, sr, sv, tl, ta, te, th, tr, uk, vi, zh-CN, zh-TW (see http://spreadsheets.google.com/pub?key=p9pdwsai2hDMsLkXsoM05KQ&gid=1)
Extra options:: <tt>:bounds</tt> - pass SW and NE coordinates as an array of two arrays to bias results towards a viewport
Documentation:: http://code.google.com/apis/maps/documentation/geocoding/#JSON
Terms of Service:: http://code.google.com/apis/maps/terms.html#section_10_12
Limitations:: "You must not use or display the Content without a corresponding Google map, unless you are explicitly permitted to do so in the Maps APIs Documentation, or through written permission from Google." "You must not pre-fetch, cache, or store any Content, except that you may store: (i) limited amounts of Content for the purpose of improving the performance of your Maps API Implementation..."
......
......@@ -27,13 +27,22 @@ module Geocoder::Lookup
return []
end
def query_url(query)
def query_url_base_params(query)
params = {
(query.reverse_geocode? ? :latlng : :address) => query.sanitized_text,
:sensor => "false",
:language => Geocoder::Configuration.language,
:key => Geocoder::Configuration.api_key
:language => Geocoder::Configuration.language
}
unless (bounds = query.options[:bounds]).nil?
params[:bounds] = bounds.map{ |point| "%f,%f" % point }.join('|')
end
params
end
def query_url(query)
params = query_url_base_params(query).merge(
:key => Geocoder::Configuration.api_key
).reject{ |key, value| value.nil? }
"#{protocol}://maps.googleapis.com/maps/api/geocode/json?" + hash_to_query(params)
end
end
......
......@@ -9,13 +9,10 @@ module Geocoder::Lookup
private # ---------------------------------------------------------------
def query_url(query)
params = {
(query.reverse_geocode? ? :latlng : :address) => query.sanitized_text,
:sensor => 'false',
:language => Geocoder::Configuration.language,
params = query_url_base_params(query).merge(
:client => Geocoder::Configuration.api_key[1],
:channel => Geocoder::Configuration.api_key[2]
}.reject{ |key, value| value.nil? }
).reject{ |key, value| value.nil? }
path = "/maps/api/geocode/json?#{hash_to_query(params)}"
"#{protocol}://maps.googleapis.com#{path}&signature=#{sign(path)}"
end
......
......@@ -28,6 +28,14 @@ class ServicesTest < Test::Unit::TestCase
result.precision
end
def test_google_query_url_contains_bounds
lookup = Geocoder::Lookup::Google.new
url = lookup.send(:query_url, Geocoder::Query.new(
"Some Intersection",
:bounds => [[40.0, -120.0], [39.0, -121.0]]
))
assert_match /bounds=40.0+%2C-120.0+%7C39.0+%2C-121.0+/, url
end
# --- Google Premier ---
......
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