# Geodata SQL statements with multiple results in the controll

**URL:** <https://www.ruby-forum.com/t/geodata-sql-statements-with-multiple-results-in-the-controll/112144>\
**Category:** Rails\
**Created:** [August 15, 2007, 10:01pm UTC](https://www.ruby-forum.com/t/geodata-sql-statements-with-multiple-results-in-the-controll/112144 "2007-08-15T22:01:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Scott\_Parks](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ac8455/32.png) [@Scott\_Parks](https://www.ruby-forum.com/u/Scott_Parks)\
**Post date:** [August 15, 2007, 10:01pm UTC](https://www.ruby-forum.com/t/geodata-sql-statements-with-multiple-results-in-the-controll/112144/1 "2007-08-15T22:01:35Z")

</div>

Hi Everyone-

In my project I need to take a zip code and get all the schools within  
the selected mile radius of that zip code. In addition I will need to  
check to see if the user selected any other items to add to the  
search.

My problem is the geo code will return multiple results and I need to  
get that result into the final sql string.

The flow is this:

Get the zip code and mile radius the user submitted - then run a query  
and get all schools within that mile radius of the user’s zip code.

Take the results of that query and create a new query with the other  
options.

The problem is the geo query returns multiple results and I need to  
access that array in the controller - is this possible by creating a  
class in the model? How would I access that array in the controller  
to prepare it for the second sql statement?

Thank you!

---

<div class="post-metadata">

**Author:** ![Scott\_Parks](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ac8455/32.png) [@Scott\_Parks](https://www.ruby-forum.com/u/Scott_Parks)\
**Post date:** [August 21, 2007, 10:35pm UTC](https://www.ruby-forum.com/t/geodata-sql-statements-with-multiple-results-in-the-controll/112144/2 "2007-08-21T22:35:52Z")

</div>

On 15 Aug 2007, at 21:00, Scott Parks wrote:

> Get the zip code and mile radius the user submitted - then run a  
> query and get all schools within that mile radius of the user’s zip  
> code.
> 
> Take the results of that query and create a new query with the  
> other options.
> 
> The problem is the geo query returns multiple results and I need to  
> access that array in the controller - is this possible by creating  
> a class in the model? How would I access that array in the  
> controller to prepare it for the second sql statement?

Have you looked at any of the geo-location plugins that are kicking  
around? There’s a (slightly out of date) comparison chart at:

[http://foss4r.dyndns.org/trac/wiki/ComparingRailsGeoPlugins](http://foss4r.dyndns.org/trac/wiki/ComparingRailsGeoPlugins)

In particular, you might like to check out acts\_as\_locatable which  
will allow you to build queries of the form:

School.find\_within\_radius(1, zip\_code)

I wrote some notes on extending that to accept other conditions. You  
can find my blog entry about it at:

> **[Extending acts\_as\_locateable](https://jystewart.net/2007/02/07/extending-acts_as_locateable/)**
>
> There have been quite a few geographically-themed Rails plugins emerging over the past few months and I decided it was time to try out acts\_as\_locateable. Acts\_as\_locateable is based on ZipCodeSear…

James.
