【发布时间】:2021-07-08 05:40:21
【问题描述】:
我正在使用 Rails Geocoder gem 对用户提交的街道地址的纬度和经度进行地理编码。我还想自动提取用户 IP 位置,以在主屏幕上显示其他用户在其位置附近提交的地址。
我想为 IPinfo 使用 API 密钥来获取用户的位置,并为 Google 使用不同的 API 密钥来对街道地址的纬度/经度进行地理编码。以前,当我调用两个 api 键时,我会收到一条警告消息,指出第一个键被第二个键覆盖,可能是因为它们具有相同的名称。
我看到上一篇文章,用户回答说他们可以通过passing the service as a lookup value 完成,但是他们是如何在 geocoder.rb 配置文件中设置 api 密钥的?他们是否更改了第二个服务的 api 名称?他们必须添加另一个配置文件吗?
任何帮助都将不胜感激。我当前的配置文件如下。我现在注释掉了 IPinfo 查找,所以我仍然可以对生产中的项目进行地理编码。谢谢。
if Rails.env.production?
Geocoder.configure(
# Geocoding options
timeout: 5, # geocoding service timeout (secs)
lookup: :google, # name of geocoding service (symbol)
# ip_lookup: :ipinfo_io, # name of IP address geocoding service (symbol)
# api_key: ENV['IPINFO_IO_API_KEY'], #API key for ip lookup service
# language: :en, # ISO-639 language code
use_https: true, # use HTTPS for lookup requests? (if supported)
# http_proxy: nil, # HTTP proxy server (user:pass@host:port)
# https_proxy: nil, # HTTPS proxy server (user:pass@host:port)
api_key: ENV['GOOGLE_GEOCODER_API_KEY'], # API key for geocoding service
# cache: Redis.new, # cache object (must respond to #[], #[]=, and #del)
# cache_prefix: 'geocoder:', # prefix (string) to use for all cache keys
# Exceptions that should not be rescued by default
# (if you want to implement custom error handling);
# supports SocketError and Timeout::Error
# always_raise: [],
# Calculation options
# units: :mi, # :km for kilometers or :mi for miles
# distances: :linear # :spherical or :linear
)
end
【问题讨论】:
-
您如何评论其他问题(或答案)以获取更多详细信息?
-
@MrUpsidown 哈哈我试图向提供答案的人发表评论,但我缺乏最低声誉分数来发表评论。你需要 15 个,而我只有 13 个。
标签: ruby-on-rails google-geocoder geocode rails-geocoder