geocoder icon indicating copy to clipboard operation
geocoder copied to clipboard

Support for PostGIS in model geocoding

Open kalsan opened this issue 1 year ago • 1 comments

Hi Alex!

I've read the discussion over in #1524 and while I fully agree that more complex geocalculations should be left to a dedicated gem, it would still be interesting to see PostGis support in geocoded_by.

Here's my current workaround:

class Foo < ApplicationRecord
  # has columns :address (string), :latitude (decimal), :longitude (decimal) and :coordinates (st_point)

  geocoded_by :address
  after_validation :geocode_postgis
  
  private

  def geocode_postgis
    geocode # fills latitude and longitude
    self.coordinates = "POINT(#{longitude} #{latitude})" # fills postgis
  end
end

While this is not too hard to accomplish, it would be even better to be able to have PostGIS support in geocoder, similar to support (geocoded_by: :coordinates)

kalsan avatar Nov 14 '24 14:11 kalsan

Thanks for this. In theory, I'm open to adding PostGIS support. However, two requirements:

  1. It gets enabled manually, through configuration, and doesn't affect anyone who doesn't have the extension installed.
  2. It doesn't make the existing SQL code significantly more complicated.

Number two is important, since the SQL part of the gem is already harder to understand and maintain than I'd like it to be. But I am open to this. If you want to write up a PR, go for it.

alexreisner avatar Nov 26 '24 18:11 alexreisner