OK so I added a google map into my site that lets users search for locations based on either city, state or by zip code that shows all shops of a certain type around them. It uses the places API to grab them, BUT I also have a table in my DB that has a bunch of shop locations set up by users. The table stores the shop details, as well as the address and the latLng (and soon the place reference number if they have a places account). What I want to do is have my google map display all the user added shop locations as well.
Im not sure how to have rails find the shops in the DB that are in proximity to the location searched for by the user.
So if I went to the site and typed in 20175 for the zip code, rails would find all the records that are close to that zip code. I guess the query would have to be based on the latLng.
This site was able to do it: http://www.checkoutmyink.com/shops and开发者_如何学C is pretty much what I want to do.
If you want to perform spatial algebra with rails, i would recommend using rGeo. It fits well with ActiveRecord and adapts to a bunch of spatial DB's (including Postgis).
Still, using spatial DB stored procedures will be far more efficient to retrieve points within a radius (using GIST index), e.g. using ST_DWithin with Postgis
精彩评论