【问题标题】:Rails Geocoder gem & Google Autocomplete API - Query Limit ReachedRails Geocoder gem 和 Google Autocomplete API - 达到查询限制
【发布时间】:2017-03-12 12:30:52
【问题描述】:

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

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

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

这是它的样子;

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

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

【问题讨论】:

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


    【解决方案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
    

    只需点击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 => "..."
    
    )
    

    【讨论】:

    • 在自动完成中 place_changed 时将 lat lng 值发送到控制器,而不是使用 Geocoder.search(params[:search]) 更好吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-04
    相关资源
    最近更新 更多