geokit / geokit-rails

Official Geokit plugin for Rails/ActiveRecord. Provides location-based goodness for your Rails app. Requires the Geokit gem.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ip geocoding: general question

knzudgt opened this issue · comments

My Rails 5 application needs to offer to users different pages according to the country of the users. I would also need geocoding in controllers. I wonder how can I get the country with geokit-rails: would the following code be correct?

country = IpGeocoder.geocode(request.remote_ip).country

Also: is there any maximum quota that the below quota has to respect?
I do not understand if geokit-rails relies on external geocoding services like google, bind or maxmind.

@knzudgt - You shouldn't need to do anything (I don't actually use this feature, I just took over maintaining this gem)

See the IP related section of the readme:
https://github.com/geokit/geokit-rails#ip-geocoding-helper

If you want to do this yourself (as your code sample is doing), you don't need the geokit-rails gem, the code could be done with just the geokit gem by itself.

Like @mnoack said, @knzudgt The geokit-rails gem is best used for adding geolocation features to your models. For example, if you have a "User" model, the user could have a lat and lng and you can find users that are near each other by calling something like User.by_distance(origin: @some_user)

If you just want plain 'ol geocoding features not specifically integrated in your models, you should just use the geokit gem, which is different from this geokit-rails gem.

As far as external services, any geocoding solution will require a third-party service unless it comes with download files. There are some services that offer free ip_address to country mappings that you can download and reference.

What CAN be done with geokit-rails without a third party solution is searching for records by distance using latitude and longitude values you've already saved in your database.