heebee313
heebee313

Reputation: 325

Automatic location detection in Ruby on Rails

A technical and legal question - what's the best rails gem to auto-detect location of a web visitor via e.g. IP? Down to granularity of state.

And is this an illegal privacy breach? Why do some sites auto-detect location and others ask for manual zip code input?

Thanks in advance!

Upvotes: 3

Views: 1619

Answers (2)

Eduardo
Eduardo

Reputation: 4382

Ruby Geocoder, check it here. It goes down to the granularity of city, well, it depends on many factors, but generally it works well. This Railscast shows some use cases.

Upvotes: 0

Jerod Venema
Jerod Venema

Reputation: 44642

You'll need some sort of IP-to-location translation database, like this one:

http://www.maxmind.com/app/ip-location

[Update: free version is here: http://www.maxmind.com/app/geolitecity]

The reason some auto-detect and others don't is a question of reliability. You can't guarantee the IP you're seeing is the actual end users IP (proxies/VPNs/etc cause problems) so while it's fine for general use, it's not practical if you're doing something for example with billing or calculating shipping costs.

Upvotes: 1

Related Questions