Rails Geocoder gem& Google自动填充API - 已达到查询限制

时间:2016-10-30 00:27:21

标签: ruby-on-rails google-maps heroku rails-geocoder

我尝试实施Google的自动填充API,当用户键入位置并按下进入时,带有标记的地图会加载到另一个页面中。它看起来与Airbnb完全一样。搜索,然后映射..

我的问题是,最近我收到“达到查询大小限制”的错误。我在这里阅读了有关此问题的所有帖子,但找不到解决方案。

基本上,当用户将地址键入字符串时,我会获得该字符串并将其用于google maps的init lat&长。我使用地理编码器gem和服务器作为Heroku。

这是它的样子;

@search = params[:search]
if !@search.nil? && @search.strip != ""  
    location =  Geocoder.search(params[:search])
    @initlat = location[0].latitude
    @initlng = location[0].longitude 
end

为什么我收到此错误,我该如何解决?

1 个答案:

答案 0 :(得分:1)

https://developers.google.com/maps/documentation/geocoding/usage-limits

Users of the standard API:

2,500 free requests per day, calculated as the sum of client-side and server-side queries.
50 requests per second, calculated as the sum of client-side and server-side queries.

付费使用

Enable pay-as-you-go billing to unlock higher quotas:

$0.50 USD / 1000 additional requests, up to 100,000 daily.

ENABLE BILLING

只需点击启用结算按钮,即可获取API密钥并设置geocoder.rb

# config/initializers/geocoder.rb
Geocoder.configure(

  # geocoding service (see below for supported options):
  :lookup => :yandex,

  # IP address geocoding service (see below for supported options):
  :ip_lookup => :maxmind,

  # to use an API key:
  :api_key => "...",

  # geocoding service request timeout, in seconds (default 3):
  :timeout => 5,

  # set default units to kilometers:
  :units => :km,

  # caching (see below for details):
  :cache => Redis.new,
  :cache_prefix => "..."

)