Pass preferred language to geonames API calls
This commit is contained in:
parent
ccebb796ab
commit
339ac9d239
1 changed files with 8 additions and 2 deletions
|
@ -194,11 +194,14 @@ class GeocoderController < ApplicationController
|
|||
# get query parameters
|
||||
query = params[:query]
|
||||
|
||||
# get preferred language
|
||||
lang = I18n.locale.to_s.split("-").first
|
||||
|
||||
# create result array
|
||||
@results = Array.new
|
||||
|
||||
# ask geonames.org
|
||||
response = fetch_xml("http://api.geonames.org/search?q=#{escape_query(query)}&maxRows=20&username=#{GEONAMES_USERNAME}")
|
||||
response = fetch_xml("http://api.geonames.org/search?q=#{escape_query(query)}&lang=#{lang}&maxRows=20&username=#{GEONAMES_USERNAME}")
|
||||
|
||||
# parse the response
|
||||
response.elements.each("geonames/geoname") do |geoname|
|
||||
|
@ -255,11 +258,14 @@ class GeocoderController < ApplicationController
|
|||
lat = params[:lat]
|
||||
lon = params[:lon]
|
||||
|
||||
# get preferred language
|
||||
lang = I18n.locale.to_s.split("-").first
|
||||
|
||||
# create result array
|
||||
@results = Array.new
|
||||
|
||||
# ask geonames.org
|
||||
response = fetch_xml("http://api.geonames.org/countrySubdivision?lat=#{lat}&lng=#{lon}&username=#{GEONAMES_USERNAME}")
|
||||
response = fetch_xml("http://api.geonames.org/countrySubdivision?lat=#{lat}&lng=#{lon}&lang=#{lang}&username=#{GEONAMES_USERNAME}")
|
||||
|
||||
# parse the response
|
||||
response.elements.each("geonames/countrySubdivision") do |geoname|
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue