获取 Rails 中的长地理位置列表时出现问题
以下脚本对我来说工作正常,但在获取一些记录(通常是 100 条记录)后失败并给出错误:--
Invalid JSON string
有时在获取大约 500 条记录后它停止获取坐标。 我需要获取 18000 个坐标,有什么建议吗?
task :populate_geolocations_reverse => :environment do
AdvocateDetail.order("id DESC").all.each do |advocate|
p advocate.id
if advocate.latitude.nil? or advocate.latitude==0 or advocate.latitude=="0"
p "fetching geolocations...:-( "
a = Geocoder.fetch_coordinates(advocate.address)
unless a.nil?
p "got geolocations... :-) "
advocate.latitude=a[0]
advocate.longitude=a[1]
p "saving geolocations...:-P "
advocate.save(false)
end
else
p " already have geolocations for this Jumped....:-)"
end
end
p "transformation done... "
end
The following script works fine for me but after fetching some records (generally 100 records) it failed and give me error:--
Invalid JSON string
and sometimes after fetching some 500 records it stop fetching coordinates.
I need to fecth some 18000 coordinates any suggestions??
task :populate_geolocations_reverse => :environment do
AdvocateDetail.order("id DESC").all.each do |advocate|
p advocate.id
if advocate.latitude.nil? or advocate.latitude==0 or advocate.latitude=="0"
p "fetching geolocations...:-( "
a = Geocoder.fetch_coordinates(advocate.address)
unless a.nil?
p "got geolocations... :-) "
advocate.latitude=a[0]
advocate.longitude=a[1]
p "saving geolocations...:-P "
advocate.save(false)
end
else
p " already have geolocations for this Jumped....:-)"
end
end
p "transformation done... "
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请记住,谷歌在满足您的请求方面有其局限性。每天大约有 1000 个唯一请求,每秒有 1 个。据我所知,Geokit 使用的服务比 google 本身更多,但它仍然可能受到限制。仔细看看这一点。
Please remember that google has its limit to serve your requests. It is around 1000 unique requests per day and 1 per second. As I know Geokit uses more services than google itself, but it still may be limited. Take a closer look on that.