ParkFinder – An sms app that finds the parks closest to a given location

In preparation for the appsforgood competition, I’m writing a small app called “Parkfinder.” It’s an app to train myself on using sms and google maps to find points of interest close to a given location.

I’m writing it on Ruby on Rails 3. And since the primary interface is intended to be SMS, the graphical aspect of the UI doesn’t matter much. Only thing that matters is being able to create the functionality and make it available via sms.

Desired functionality: Users should be able to sms their address and receive back a list of parks nearby.

To do that, we definitely need at least one model, which is Parks.

I generated a scaffold with the following fields:

  • name
  • openhours
  • latitude
  • longitude
  • address1
  • address2
  • city
  • state
  • zip
  • description

$ rails generate scaffold Park name:string open:string lat:string long:string address1:string address2:string city:string state:string zip:string description:string

I also created a user, just because I thought I’d need one, but really, I should wait until later for this.

$rails generate scaffold User name:string phonenumber:string email:string confirmationcode:string notes:string

So I destroyed it right after I made it, to enforce the discipline of not just making things for the sake of them. Bad developer!

$ rails destroy scaffold User

Now that the Parks model is made, the next step is to integrate it with some sort of api that allows me to turn addresses into latitude/longitude coordinates, so we’ll have this information to do a rough determination of distance to a given address.

The Google maps api allows geocoding fairly easily:

As we can see by going to the documentation at that link the instructions are:

A Geocoding API request must be of the following form:

where output may be either of the following values:

  • json (recommended) indicates output in JavaScript Object Notation (JSON)
  • xml indicates output as XML

To access the Geocoding API over HTTPS, use:

HTTPS is recommended for applications that include sensitive user data, such as a user’s location, in requests.

In either case, certain parameters are required while some are optional. As is standard in URLs, all parameters are separated using the ampersand (&) character. The list of parameters and their possible values are enumerated below.

The Geocoding API defines a geocoding request using the following URL parameters:

  • address (required) — The address that you want to geocode.*
  • OR

  • latlng (required) — The textual latitude/longitude value for which you wish to obtain the closest, human-readable address.*
  • bounds (optional) — The bounding box of the viewport within which to bias geocode results more prominently. (For more information see Viewport Biasingbelow.)
  • region (optional) — The region code, specified as a ccTLD (“top-level domain”) two-character value. (For more information see Region Biasing below.)
  • language (optional) — The language in which to return results. See the supported list of domain languages. Note that we often update supported languages so this list may not be exhaustive. If language is not supplied, the geocoder will attempt to use the native language of the domain from which the request is sent wherever possible.
  • sensor (required) — Indicates whether or not the geocoding request comes from a device with a location sensor. This value must be either true or false.

I tested this out by going to:,+Mountain+View,+CA&sensor=false

This allows us to see the output as xml.

Ok, so I was thinking the next step is to write a function that will take an address and do a geocode lookup on the address, so that I could store lat and long data in the database. I would then use that function to automatically do a geocode lookup of the user’s address, so I could return the distances of the nearest parks. Then I thought, “Hmm… I wonder if there’s a similar http request I could use to get the distance to the nearest park.”  Turns out you can do a google maps api lookup, to figure out the walking distance between two points pretty easily, but that still doesn’t solve the issue of how to determine which those closest stores are. The easiest way to do that is probably by looking at the difference between geocode numbers. Then if we want to, we can do a google maps call to determine the walking distance, but that’s not required so I’ll leave it out.

XML directions between 424 Ellis St and Golden Gate Park, in San Francisco.

Maps api information here:

Ok, so back to the old keying board… need to make a function that takes an address, uses it to call google maps, and returns back latitude and longitude.

A quick search on github turns up a rubygem by ApneaDiving called “Google Maps for Rails” that was recently updated and released under the MIT license.

So I’ll try to incorporate that…

Ok, just checked in to git and heroku. About to include the gmaps4rails gem

Comments are closed.