Skip to content

Commit

Permalink
experimental polygon support
Browse files Browse the repository at this point in the history
  • Loading branch information
starswan committed Dec 4, 2024
1 parent d750a06 commit cc8ce5b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/models/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,15 @@ def limit_by_location(vacancies, location, radius_in_miles)
else
#TODO: add polygon support? 'within?' function for polygons doesn't support distance like ST_Within function does
radius_in_metres = convert_miles_to_metres radius_in_miles
coordinates = Geocoding.new(query).coordinates
search_point = RGeo::Geographic.spherical_factory.point(coordinates.second, coordinates.first)
vacancies.select { |v| v.organisations.map(&:geopoint).any? { |point| search_point.distance(point) < radius_in_metres } }

polygon = LocationPolygon.with_name(query)
if polygon.present?
vacancies.select { |v| v.organisations.map(&:geopoint).any? { |point| point.buffer(radius_in_metres).intersects?(polygon.area) } }
else
coordinates = Geocoding.new(query).coordinates
search_point = RGeo::Geographic.spherical_factory.point(coordinates.second, coordinates.first)
vacancies.select { |v| v.organisations.map(&:geopoint).any? { |point| search_point.distance(point) < radius_in_metres } }
end
end
end
end
Expand Down

0 comments on commit cc8ce5b

Please sign in to comment.