The geocoder gem provides a #location
method on the request object (source) which returns a location result with latitude and longitude:
request.location
=> #<Geocoder::Result::Freegeoip:0x007f8ecca5d608
@cache_hit=true, @data= {
"ip"=>"199.21.87.210", "country_code"=>"US",
"country_name"=>"United States", "region_code"=>"CA", "region_name"=>"California", "city"=>"Berkeley", "zipcode"=>"", "latitude"=>37.8716, "longitude"=>-122.2728, "metro_code"=>"807", "areacode"=>"510"
}>
To test this functionality in the browser, try using ngrok to expose your local server and throw some debugger statements in your controller to see what the request.location
object looks like.