10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'app/models/google_maps_api/geocode.rb', line 10
def geocode(address_string)
raise ArgumentError.new('address_string cannot be blank') if address_string.blank?
begin
return nil unless result = send_request("#{BASE_URI}?address=#{escape_javascript address_string}")
rescue SocketError => e
if Rails.env.development? || Rails.env.test?
Rails.logger.warn 'not connected to the Internet... faking geocode API call'
return 37.792855, -122.403166
end
raise e
end
location_result = result['results'][0]['geometry']['location']
[ location_result['lat'], location_result['lng'] ]
end
|