Pregunta

I'm trying to use Geocoder to simply return results near a given latitude and longitude, my table has latitude and longitude columns although they're spelt 'model'_latitude and 'model'_longitude.

I don't need to geocode the object as I don't use an address, the latitude and longitude are stored via parameters at creation and I want to retrieve results using the near method.

Is this even possible with this gem? If not any suggestions on something more suited?

EDIT:

For a little more info, this is what I have so far. In the model class:

geocoded_by :latitude  => :game_latitude, :longitude => :game_longitude
after_validation :geocode

and then I'm trying to find games within 50km with:

Game.near([latitude, longitude], 50, :units => :km)

and the error I'm receiving is 'Unknown column games.latitude' so it's obviously not trying to look for game_latitude

¿Fue útil?

Solución

geocoded_by is for address to lat/lon. You want reverse_geocoded_by. No need for any after hooks at all I don't think.

Just this in your Game model:

reverse_geocoded_by :game_latitude, :game_longitude

See the last lines of this section:

https://github.com/alexreisner/geocoder#activerecord

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top