我知道我们需要使用唯一的 API key 来访问 Google Geocoding API。我在我的应用程序中使用 Rails Geocoder Gem,发现它使用 Google Geocoding API。我找不到任何配置文件定义用于访问 Google API 的 API key 。Geocoder gem 如何访问 Google API。
最佳答案
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 supports Google api keys for Google Premier accounts only.
但是你可以使用客户端框架来做到这一点,而不是把它放在服务器上
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
关于ruby-on-rails - Rails Geocoder Gem 如何访问 Google API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26622841/