Skip to content

Instantly share code, notes, and snippets.

@mager
Created July 1, 2011 05:36
Show Gist options
  • Save mager/1057932 to your computer and use it in GitHub Desktop.
Save mager/1057932 to your computer and use it in GitHub Desktop.
Get area code from IP address using SimpleGeo Places & Ruby
SimpleGeo::Client.set_credentials(ENV['SIMPLEGEO_KEY'],ENV['SIMPLEGEO_SECRET'])
resp = SimpleGeo::Client.geocode_from_ip()
options = {:num=>1}
place = SimpleGeo::Client.get_places(resp[:query][:latitude], resp[:query][:longitude], options)
phone = place[:features][0][:properties][:phone]
@area_code = phone[3..-10] # Phone number format: "+1 XXX XXX-XXXX"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment