Skip to content

GeocodingAndMapping

Shawna C Scott edited this page Jul 27, 2014 · 2 revisions

Calagator's use of location information

Introduction

Calagator now geocodes (that is, it tries to determine a latitude/longitude location based on address information) new venues as they're created. At the moment, there's no visible interface to this mechanism or its success, but that's coming soon.

This page describes how the process works at the moment (it'll be updated as the process changes), and provides a collection point for more ideas.

Our use of GeoKit

We geocode using the GeoKit plugin - Scott Becker had used it before, and it turned out to be really easy to use. Its easy interface is "acts_as_mappable", to geocode make ActiveRecord models automatically upon create, but any failure to geocoding would prevent validation, which seems bad when we want unattended batch importing to be smooth.

Instead, we opted to call GeoKit explicitly to gain more control: in addition to silencing failures to geocode, we also attempt to geocode whenever we save a venue that doesn't have a location yet. A user editing a venue can also check a box to force re-geocoding.

When we geocode, we use the full_address (that is, the concatenation of all the broken-out addressing fields) unless it's blank, in which case we use "raw" address - if it's blank too, we do nothing.

Our use of the GoogleMaps plugin

After looking at several plugins that assist with Google mapping, I picked GoogleMaps. (It's called gmaps-on-rails on Google Code; I checked it into our project as gmaps_on_rails because plugin names need to be valid symbols.)

I chose it because it did what we need it to without requiring extra JavaScript work; I wrote a little adapter helper that makes displaying a map of anything with a location and a title a one-liner ("<%= google_map @event %>"). I made a few changes to the plugin along the way (tagged in the sources with "CALAGATOR"); I've contacted the author about including them upstream.

Configuration

GeoKit and the mapping plugin use the Google Maps API, which requires a key; these keys are tied to a Google user's identity, and though the per-key daily geocoding limits are high, it'd still be bad for a key to be published, so:

  • Calagator reads the key from "config/geocoder_api_key.yml" at startup, if it's present. If this file isn't present, no geocoding is performed.
  • This file isn't checked into the source tree; instead, copy config/geocoder_api_key.yml.example to config/geocoder_api_key.yml and put your own key into it, following the instructions in it.

INITIAL REVIEW NEEDED

Clone this wiki locally