I have a Rails model that uses the PostGIS POINT type to store location coordinates. How can I request all the locations that are contained in the bounding box? The bounding box comes with Google Maps as follows:
/locations?within=40.766159%2C-73.989786%2C40.772781%2C-73.979905&per_page=500
then in my model I have the ability to handle this, but I can’t figure out how to get the request correctly:
scope :within, ->(box_string) { sw = box_string.split(",")[0..1].reverse.map {|c| c.to_f} ne = box_string.split(",")[2..3].reverse.map {|c| c.to_f} box = "BOX3D(#{sw[0]} #{sw[1]}, #{ne[0]} #{ne[1]})" where( ***WHAT DO I DO HERE?*** ) }
Avishai
source share