alexreisner/geocoder

Multi-dimensional coordinates not returning data

SylarRuby opened this issue · 1 comments

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

  • Geocoder version: gem "geocoder", "~> 1.8"
  • Rails version: 7
  • Database (if applicable): MySQL
  • Lookup (if applicable): ??

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

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.