Last active
December 20, 2015 12:59
-
-
Save Breefield/6135481 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Logs are saying: | |
# | |
# Cache read: geocoded/New York, NY | |
# Cache fetch_hit: geocoded/New York, NY | |
# Google Geocoding API error: over query limit. | |
# | |
# Seems to hit a match, then query google anway | |
def self.geocode(address) | |
location = Rails.cache.fetch("geocoded/#{address}") do | |
begin | |
location = Location.new(:address => address) | |
location.valid? | |
{:latitude => location.latitude, :longitude => location.longitude} | |
rescue Geocoder::OverQueryLimitError => e | |
# If over limit try again until it works... *sigh* | |
self.geocode(address) | |
end | |
end | |
return location | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment