所以我想爲美國和加拿大編寫我自己的地理編碼數據庫,因爲我需要令人難以置信的速度,並且沒有速率限制。我爲軌道批量地理編碼提供了以下算法,但是我想知道是否有更好的方法來加載最初的一批城市。我一直在進行基準測試,並且我已經將其歸結爲這種算法,該算法在大約19秒內給出了1000個地理編碼,覆蓋範圍大約爲50%。數據庫地理編碼軌道
我的問題是,會有操作,而不是重新查詢試圖「向下鑽取」當數據庫更好的辦法?
ids = City.where('lower(name) IN (?)', locations).pluck(:id) # Eager load the only possible results
results.find_each do |r|
#next if r.location = 'EXACT'
names = r.location.split(',')
state = get_state(names)
city = City.where(:id => ids, :state => state[0]).where('lower(name) IN (?)', names).first # Drill down to the appropriate state
if city.nil?
city = City.where(:id => ids).where('lower(name) IN (?)', names).first # Hail Mary
end
# Return if nil?
if city.blank?
puts "Oh no! We couldn't find a city for #{r.location}"
else
# Finally, the city
puts "Selected #{city.name} for #{r.location}"
r.latitude = city.latitude
r.longitude = city.longitude
r.save
end
end
你正在做我想做的事情。你如何設置Geocoder來調用你的數據庫而不是API?因爲我不想使用Google或任何其他服務來撥打電話。我正在嘗試設置,以便用戶可以在附近找到其他註冊成員。因此,我需要使用拉鍊代碼調用具有緯度/經度的zipcode數據庫。 – xps15z
通過電子郵件告知我您的具體需求。郵政編碼比城市/地名更容易。我一直計劃公開採購這個項目/想法,因爲這並不難。 bwheeler96 [at] gmail.com – OneChillDude