Ruby
Contributed by Robert Schäfer - https://github.com/roschaefer to the popular Geocoder - https://github.com/alexreisner/geocoder - gem.

Installation

1
gem install geocoder
Copied!

Configuration

First create a Rails initializer with basic configuration
1
rails generate geocoder:config
Copied!
Then update your config/initializers/geocoder.rb file to look like below;
1
# config/initializers/geocoder.rb
2
Geocoder.configure(
3
4
ip_lookup: :ipdata_co,
5
6
# to use an API key:
7
api_key: "test",
8
)
Copied!

Usage

1
results = Geocoder.search("172.56.21.89")
2
results.first.coordinates
3
=> [30.267153, -97.7430608]
4
results.first.country_name
5
=> "United States"
Copied!
Last modified 2yr ago