How to get geo location with the help of IP address

i am developing a product where i need to know from wich country the user is logged in .! and display things according to his geolocation . can any one please help me out with this

Rajesh B. wrote in post #974156:

i am developing a product where i need to know from wich country the user is logged in .! and display things according to his geolocation . can any one please help me out with this

Perhaps you want to use the new HTML 5 geolocation features. If not, Google has a similar API available to the public. This is an HTML/JS issue and has nothing to do with Rails.

Best,

Thanks Marnen.

Rajesh B. wrote in post #974156:

i am developing a product where i need to know from wich country the user is logged in .! and display things according to his geolocation . can any one please help me out with this

Great! Geolocation is always fun.

Perhaps you want to use the new HTML 5 geolocation features. If not, Google has a similar API available to the public. This is an HTML/JS issue and has nothing to do with Rails.

You may be correct in this statement, but there’s also the option of segmenting the content on the server side. I.e., in Rails. It can arguably also be a nice attribute to have on a user model for future send-outs or similar.

Have a look at https://github.com/cjheath/geoip. Then check out http://www.maxmind.com/app/ip-location.

Good luck.

Didde Brockman wrote in post #974306:

Or you could use the geoip gem :slight_smile:

http://ruby.about.com/od/gems/a/geoip.htm

Didde Brockman wrote in post #974306:

Rajesh B. wrote in post #974156:

i am developing a product where i need to know from wich country the user is logged in .! and display things according to his geolocation . can any one please help me out with this

Great! Geolocation is always fun.

Perhaps you want to use the new HTML 5 geolocation features. If not, Google has a similar API available to the public. This is an HTML/JS issue and has nothing to do with Rails.

You may be correct in this statement, but there's also the option of segmenting the content on the server side. I.e., in Rails.

Well, of course Rails should *deal with* the data once acquired. But acquiring the user's location is a job for the client side, isn't it?

I'm not so sure. It depends on the use case, IMHO.

For example. Say you have http://www.mysite.com/ which needs to redirect the visitor to http://www.mysite.co.uk/ if the originating IP resolves to the UK. Using your method, a page would need to load, determine the geographical location and then use meta refresh or a Javascript in order to perform the actual redirect.

Using GeoIP on the server side, a redirect_to in the controller could take care of it all in one quick action.

But again, it all depends on what you need to do. If it's a matter of simply varying some sort of UI element, the client side way makes sense.

Your mileage may vary :slight_smile:

+1

If the OP only needs the *country* identified, GeoIP on the server is the easiest solution.

For any finer granularity, GeoIP (or any IP-based system) is not very reliable. (At the moment I'm in a moving vehicle south of Pismo Beach California, and GeoIP thinks I'm in Manteca -- *way* off.)

But the client-side solutions are still a work in progress too, AFAICT :slight_smile:

FWIW,

Hi, if you want to maintain the data yourself then you might want to consider of getting the data from geolocation providers. We use IP2Location and I think there have Ruby solution available too. Try IP2Location IP Geolocation Ruby Library | IP2Location.

Thanks all :slight_smile: