https://github.com/alexreisner/geocoder
I can't find documentation to show the visitor's city from ip address? I know how to with HTML5, but I would like to use the value geocoder has. Thanks
It took a couple of hours for me to realize that the answer is pretty simple:
request.location.city
Geocoder page has this example but I thought that I would need to declare request but no, nothing more is needed.
If you don't have Geocoder you have to install the gem but nothing besides that.
How I did it was -
location = Geokit::Geocoders::IpGeocoder.geocode(source_ip)
city = location.city
country = location.country
Here, source_ip is a string object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With