Fergus Morton
Fergus Morton

Reputation: 45

Trying to display content on side bar based on the visitors location

I am trying to display a list of salons that correspond to the users location on the show view of treatment.

The two tables don't have a direct relationship.

I have installed the geokit gem and now I am trying to work out if I need to add additional columns also to salon and user to store their respective co-ordinates(lat,lng) so that I can compare them using a scope.

How to I retrieve the users location via their IP and store it?

If someone could show me some example code of what the model/view and controllers should look like it would be of great help.

Upvotes: 0

Views: 65

Answers (1)

Rajarshi Das
Rajarshi Das

Reputation: 12320

You can get the location using geokit-rails gem by following way

location = IpGeocoder.geocode('12.215.42.19')

The ip is 12.215.42.19

Also

The Multi-Geocoder will also geocode IP addresses and provide failover among multiple IP geocoders. Just pass in an IP address for the parameter instead of a street address. Eg:

location = Geocoders::MultiGeocoder.geocode('12.215.42.19')

Upvotes: 0

Related Questions