Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current position via geocoder. Rails

I'm trying to get current coordinates using geocoder.

But

request.location.latitude
request.location.longitude 

always returns 0.0 and 0.0 for me. Is it possible to find geolocation coordinates using geocoder?

Thanks in advance!

like image 487
Mike Andrianov Avatar asked Mar 21 '26 18:03

Mike Andrianov


1 Answers

This is because in development environment your ip address is 127.0.0.1 which is not a real Internet ip address. This will work return latitude and longitude for an Internet ip.

You can configure ip address in development environment, to do this add following lines in app/config/environment/development.rb

class ActionDispatch::Request
    def ip
      "216.52.207.74"
    end
end

Restart your server and now it should return valid latitude and longitude

like image 116
Saqib Avatar answered Mar 23 '26 08:03

Saqib



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!