获取 Rails 中的长地理位置列表时出现问题

发布于 2024-10-13 12:42:09 字数 772 浏览 3 评论 0原文

以下脚本对我来说工作正常,但在获取一些记录(通常是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素罗衫 2024-10-20 12:42:09

请记住,谷歌在满足您的请求方面有其局限性。每天大约有 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文