我知道我們需要使用唯一的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. Rails中的Ruby Geocoder gem問題
- 2. 關於geocoder gem的問題
- 3. Rails Gem Geocoder Lookup method not obeying /config/initializers/geocoder.rb
- 4. Google oath2通過Ruby,Rails和'omniauth-google-oauth2'gem訪問失敗
- 5. Geocoder gem是否可以使用Google API密鑰?
- 6. 渲染結果爲Form rails/gem geocoder
- 7. Rails Geocoder Gem Passenger無法啓動
- 8. Google Geocoder API請求超出
- 9. Google geocoder vs地方API
- 10. Google Geocoder加載問題
- 11. 如何使用Ruby on Rails中的Geocoder gem獲得postal_code?
- 12. 如何從NodeJS REST API訪問Google API?
- 13. 將索引中的meta_search gem與現有geocoder gem search(rails)集成
- 14. Rails LinkedIn API gem
- 15. Google Plus API訪問
- 16. Node.js:如何訪問Google AdWords API
- 17. 如何訪問Google日曆API方法
- 18. 如何在ruby中訪問Google Contacts API
- 19. 如何使用Google API下線訪問
- 20. Rails API + AngularJS + Websocket-Rails gem
- 21. 訪問API的Rails
- 22. 如何外化Rails模型(api/gem/plugin)
- 23. Rails Gem Geocoder不遵循每個請求語言設置?
- 24. [google-maps-api-3] [Geocoder]特殊字符:Ñ
- 25. GeoGoogle - Google Geocoder Java API已被棄用?
- 26. Google Maps API v3.5 Geocoder語言選項
- 27. 用戶訪問推薦的Rails gem?
- 28. Google geocoder v2和v3
- 29. Google Map API v2 - GeoCoder - 如何自定義標記?
- 30. 如何通過gem訪問rails項目中的文件?