alexreisner / geocoder

Complete Ruby geocoding solution.
http://www.rubygeocoder.com
MIT License
6.35k stars 1.19k forks source link

Multi-dimensional coordinates not returning data #1625

Closed SylarRuby closed 1 year ago

SylarRuby commented 1 year ago

Expected behavior

Should see a list of venues

Actual behavior

Empty venue

Steps to reproduce

coordinates = [
  [52.63295691696663, -2.0789909362792973],
  [52.63295691696663, -1.8656158447265625],
  [52.516950299719944, -2.0789909362792973],
  [52.516950299719944, -1.8656158447265625]
]

# Returns an empty array
Venue.near(coordinates, 100, units: :mi)

Environment info

What works?

coordinates.map{ |coords| Venue.near(coords, 100, units: :mi) }

Do I have to loop the coordinates instead of passing in the coordinates directly?

Actual work around:

coords = JSON.parse(params[:coords])
radius = 100

results = []
coords.each do |coord|
  venues = Venue.near(coord, radius, units: :mi)
  results.concat(venues)
end
alexreisner commented 1 year ago

I think what's happening here is that you're passing 4 coordinates when the method expects 2: the southwest followed by the northeast. Your first two coordinates are on a line so it's effectively searching in a rectangle with zero area. Does that make sense? Feel free to re-open the issue if this doesn't resolve it.