开发者

issue in fetching long list of geolocations in rails

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 geo开发者_如何学Golocations... :-) "
       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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜