Skip to content

Instantly share code, notes, and snippets.

@Breefield
Last active December 20, 2015 12:59
Show Gist options
  • Save Breefield/6135481 to your computer and use it in GitHub Desktop.
Save Breefield/6135481 to your computer and use it in GitHub Desktop.
# 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