I'm having trouble iterating through two arrays using the haversine Ruby gem.
I'll post the full gist here but give you an idea of what I'm trying to accomplish.
https://gist.github.com/ornerymoose/c4a45540304706e78191894dfe6b2539
We have a fiber network. Just think about it as lines on a map. I have all the lat/long pairs that make up this network, roughly 24,000 rows.
We have potential customers that are in the area of the fiber network. We want to see what customers are within 1,000 feet of our network. For our potential customers, we have roughly 3,000 rows.
The Haversine formula takes four arguments: lat1, long1, lat2, long2. The first two will represent the customer, the second two will represent the fiber network.
For a hardcoded customer location, I can do this and it returns the correct value in feet. Verified via Google Earth.
File.open('distance-output.csv', 'w') do |csv_object|
lat.zip(long).each do |lat_locs,long_locs|
csv_object << Haversine.distance(28.59569, -81.21464, lat_locs.pop.to_f, long_locs.pop.to_f).to_feet
csv_object << "\n"
end
end
Now, how would I implement the same type of .zip
setup for the customer lat/long data?
If I wrap lat.zip(long).each do |lat_locs,long_locs|
in the customer .zip
, it returns values but incorrect (like, really incorrect). If I wrap the customer zip
block in lat.zip(long).each do |lat_locs,long_locs|
, the returned values are also incorrect.
Any input on this is greatly appreciated.