4

I am working in ruby on rails. Rails version 3.1.1. I have been using Geocoder gem to geocode locations based on street addresses and it is working just fine. Now I have been trying to use my visitors ip-address to locate them.

I have tried

result = request.location

and

ip = request.ip
result = Geocoder.search(ip)

The first option returns an nil, the second gives me a correct ip-address and an empty array.

Are there any configurations I need to do in order for this to work?

Any other smoother alternatives? I was looking into using HTML5 or some javascript in the browser, but that would not be optimal since I want to use the location on the server side.

Albin
  • 2,912
  • 1
  • 21
  • 31
  • It looks like the IP address you are getting cannot be traced to a specific location. What happens if you type the IP in here: http://whatismyipaddress.com/?gclid=CKWB55rJwK4CFQZ_hwodjDlvug – ScottJShea Feb 28 '12 at 11:33
  • I have tried the same IP on a few sites, and they find me. whatismyipaddress.com found me aswell. – Albin Feb 28 '12 at 12:47
  • 1
    I seem to have the same problem; geocoding by IP did work, but does not work anymore. – jessecurry Jun 11 '12 at 23:53
  • Did not work for me either. I even tried changing the service from FreeGeoIP to Nominatim/Google/Yandex. But no results – ArjunUrs Nov 09 '12 at 15:21
  • @AlbinSvensson This might be too late to respond, or if you found a different solution, but this is what I've done. In my controller, I created a variable, i.e. like `@client_ip = request.ip`,`@city = request.location.city` and etc and then was able to use those in my views `<%= @city %> and etc. – Xander Mar 25 '13 at 16:45

1 Answers1

1

I had the same problem this week, the search return null, please take a look at my solution

error in request.location ruby geocoder

The solution was increment the timeout.

Community
  • 1
  • 1
rderoldan1
  • 3,517
  • 26
  • 33