Loose Change / GeoCouch Demo
Install GeoCouch (instructions available via github).
Clone this repository.
Have Ruby 1.9 and bundler installed on your system, and run
bundle installfrom the project root.
rake db:seedsfrom the project root, which will copy the lake data from lakes.csv into CouchDB (see db/seeds.rb to see how this happens). The lakes data is via the USGS.
rails serverand check it out!
How It Works
The Lake model, in app/models/lake.rb, is a simple LooseChange model
with two normal properties (
state) and a spatial point
loc, which is set as a
By declaring the geo_point property, LooseChange gives us a
by_bounding_box method that allows us to find all documents whose
position is within the bounding box defined by two points (SW and NE
corners, respectively). We find those documents and return them as
JSON to the UI.
The Front End
HTML5 geolocation API (see a good demo at html5demos.com) to get the user's location, or fall back on a
predefined point near the middle of the US. Once we have the center
position, we initialize the map (see documentation for the Google
Maps API). When
the map is drawn, and any time the map is redrawn, we call a function
retrieveLakes which makes an AJAX call to the application to
retrieve a JSON array of lakes within the current bounds. For each
lake, we generate a marker with its name and state and place it on the
map. On re-draws, v3 of the Google Maps API requires you to manually
clear the markers from the map.