tags:

views:

34

answers:

0

I'm developing an app where a user can search by address and get all results within a certain mile radius. I have that part working with the geokit gem and plugin in Rails. But, I'm trying to figure out the best way to to show a list of nearby cities and the number of matches per city.

I could iterate over the result set and take out the unique city entries of those results until I have a big enough list. This means if the result set is small, to the point where all of them are in the same city, I'd have to keep calling the database (outside of the range specified) until I have enough cities to complete a good list.

So my question is if there is a more efficient way of doing that. Something like: find_all_cities_near('90210').limit(8) so, the zip code is geocoded and nearby cities are returned.