ジオコードを使用してIP経由で国、州、都市を取得していますが、Freegeoipの精度は高くありません。Googleを使用するようにジオコーダーを構成しました。例:
geocoder.rb
Geocoder.configure do |config|
config.lookup = :google
config.api_key = "API_KEY"
config.timeout = 5
config.units = :km
end
ただし、ジオコーダーはgoogleではなくFreegeoipを使用します。Googleを使用してIP経由で国、州、都市を取得できるかどうかはわかりません。どのジオコーダープロバイダーがGEOIPを使用できますか?
my_controller.rb
@result = request.location.to_yaml
見る
--- !ruby/object:Geocoder::Result::Freegeoip cache_hit: data: city: Caxias Do Sul region_code: "23" region_name: Rio Grande do Sul metrocode: "" zipcode: "" longitude: "-51.1833" latitude: "-29.1667" country_code: BR ip: 201.22.227.49 country_name: Brazil