【问题标题】:How does Rails Geocoder Gem access Google API?Rails Geocoder Gem 如何访问 Google API?
【发布时间】:2014-10-29 04:34:15
【问题描述】:

我知道我们需要使用唯一的 API 密钥来访问 Google Geocoding API。我在我的应用程序中使用 Rails Geocoder Gem,发现它使用了 Google Geocoding API。我找不到任何配置文件定义用于访问 Google API 的 API 密钥。Geocoder gem 如何访问 Google API。

【问题讨论】:

    标签: ruby-on-rails ruby google-api google-geocoder rails-geocoder


    【解决方案1】:
    Geocoder.configure(
      :lookup => :google_premier,
      :api_key => [ 'GOOGLE_CRYPTO_KEY', 'GOOGLE_CLIENT_ID', 'GOOGLE_CHANNEL' ],
      :timeout => 5,
      :units => :km,
    )
    

    https://github.com/alexreisner/geocoder

    这里还有一个链接:http://hankstoever.com/posts/11-Pro-Tips-for-Using-Geocoder-with-Rails

    一些常见的配置选项是:

    你应该看看这个答案:Does Geocoder gem work with google API key?

    上面写着:

    Geocoder 仅支持 Google Premier 帐户的 Google api 密钥。

    但您可以使用客户端框架来执行此操作,而不是将其放在服务器上

    https://developers.google.com/maps/articles/geocodestrat

    几天前我用 ruby​​ 写过类似的东西,如果有帮助的话:

    require 'net/http'
    require "resolv-replace.rb"
    require 'json'
    
    url = URI("https://maps.googleapis.com/maps/api/geocode/json")
    puts "enter country code"
    c_code = gets
    puts "enter zip code "
    zip = gets
    
    url.query= URI.encode_www_form({ address: "#{c_code.chomp}+#{zip.chomp}" })
    res = Net::HTTP::get_response(url)
    
    json_data = res.body if res.is_a?(Net::HTTPSuccess)
    
    data = JSON.parse(json_data)
    p data
    

    【讨论】:

    • 嘿,既然一切都通过 Google API 云平台进行,那么为 Google 生成凭据的最新方法是什么?我们需要Service account key 吗?我可以找到私钥和客户端 ID,但“Google 频道”呢?
    • @CyrilDuchon-Doris 很抱歉,我已经有一段时间没有处理这个问题了。您可能需要问另一个问题或尝试使用谷歌搜索。这就是为什么我尽量避免使用涉及 3rd 方 API 集成的代码。
    猜你喜欢
    • 2017-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-04
    • 1970-01-01
    相关资源
    最近更新 更多