我知道我們需要使用唯一的API密鑰才能訪問Google地理編碼API。我在我的應用程序中使用了Rails Geocoder Gem,並發現它使用了Google地理編碼API。我無法找到任何配置文件定義訪問Google API的API密鑰。Geocoder gem如何訪問Google API。Rails Geocoder Gem如何訪問Google API?
4
A
回答
3
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 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
相關問題
- 1. 關於geocoder gem的問題
- 2. Geocoder gem是否可以使用Google API密鑰?
- 3. Rails Geocoder Gem Passenger無法啓動
- 4. 渲染結果爲Form rails/gem geocoder
- 5. Google Geocoder加載問題
- 6. 如何從NodeJS REST API訪問Google API?
- 7. 如何在ruby中訪問Google Contacts API
- 8. 如何訪問Google日曆API方法
- 9. 如何使用Google API下線訪問
- 10. [google-maps-api-3] [Geocoder]特殊字符:Ñ
- 11. Rails Gem Geocoder不遵循每個請求語言設置?
- 12. 訪問API的Rails
- 13. 如何外化Rails模型(api/gem/plugin)
- 14. 用戶訪問推薦的Rails gem?
- 15. Google Map API v2 - GeoCoder - 如何自定義標記?
- 16. rails geocoder gem找到具有匹配地址的用戶
- 17. 如何訪問Google AnalyticsAPI?
- 18. Rails的任何Google + 1按鈕gem?
- 19. 使用Nodejs訪問Google Api
- 20. Google Contacts API - 只讀訪問
- 21. wash_out訪問soap_config方法的gem錯誤
- 22. Ruby on Rails的Jira API gem?
- 23. amazon-product-advertising-api gem + Rails 3
- 24. 的Rails:訪問CoinmarketCap API
- 25. gmaps4rails與geocoder gem有衝突嗎?
- 26. Rails 3.1的gmaps4rails gem是否允許使用Google Maps API密鑰?
- 27. Google PHP API離線訪問問題
- 28. Geocoder寶石 - Ruby On Rails - 外鍵(belongs_to)
- 29. Rails Rspec和Geocoder IP查找
- 30. 如何使用datetimepicker-rails gem