Thursday, May 19, 2016

How to find the location based on IP address

Use geocoder gem:

rails c
> Geocoder.search('209.249.19.172').first
 => #"209.249.19.172", "country_code"=>"US", "country_name"=>"United States", "region_code"=>"CA", "region_name"=>"California", "city"=>"Moraga", "zip_code"=>"94556", "time_zone"=>"America/Los_Angeles", "latitude"=>37.8381, "longitude"=>-122.1026, "metro_code"=>807}, @cache_hit=nil>

No comments:

Post a Comment