oka*_*56k 1 google-maps ruby-on-rails rails-geocoder ruby-on-rails-4
如果已达到API查询限制,如何询问Geocoder gem地址?
csv.each_with_index do |row, i|
if !row[:location_1].nil?
coords = row[:location_1]
g = Geocoder.address(coords)
row[:address] = g
end
if g.include?('over query limit')
p "limit hit"
end
end
Run Code Online (Sandbox Code Playgroud)
我不确定要问哪个对象.控制台中出现错误:
Google Geocoding API error: over query limit.
Run Code Online (Sandbox Code Playgroud)
但我不知道如何在代码中检查它.有帮助吗?
您可能希望将您包装Geocoder.address在开始/救援块中:
csv.each_with_index do |row, i|
if !row[:location_1].nil?
coords = row[:location_1]
begin
g = Geocoder.address(coords)
row[:address] = g
rescue Geocoder::OverQueryLimitError
p "limit hit"
end
end
end
Run Code Online (Sandbox Code Playgroud)
只需注意,您可能希望在执行此操作后突破救援条款中的循环,这样您就不会使用错误请求向地理编码Web服务发送垃圾邮件.
请参阅地理编码器错误.
| 归档时间: |
|
| 查看次数: |
1149 次 |
| 最近记录: |