Home > code > Setting up geokit.

Setting up geokit.

July 3, 2010 No Comments

A quick checklist for creating a new app with geolocation on heroku’s 1.8.7 stack… so you can use the count method to your heart’s content. I’m sure that there’s something I’ve missed, but it’s a start…

  1. sudo gem install geokit (if you haven’t already)
  2. script/plugin install git://github.com/andre/geokit-rails.git
  3. for new app, create heroku app (
    • on 1.8.7 stack – heroku create APPNAME –stack bamboo-ree-1.8.7 –remote REMOTENAME
    • add the following to app’s .gems file:
      1
      2
      3
      rails -v 2.3.5
      pg
      geokit --version '=1.5.0'
  4. get new developer keys for your heroku app
    • http://developer.yahoo.com/maps/simple/
    • http://code.google.com/apis/maps/signup.html
  5. add config.gem “geokit” to config/environment.rb
  6. edit your application controller file:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    include Geokit
    include Geokit::Geocoders
    include Geokit::IpGeocodeLookup

    class ApplicationController < ActionController::Base
      helper :all
      protect_from_forgery
      geocode_ip_address
     
      before_filter :geokit

      def geokit
        store_ip_location
        @current_location = session[:geo_location]  # @current_location is a GeoLoc instance.
      end
      def store_location
        session[:return_to] = request.request_uri
      end
     
    end

From this point forward, the geocoding methods of the Geokit gem are available. There’s more that needs to be done if you want to treat one of your models as geolocatable… but I’ll pick that up later :)

No related posts.

Bookmark and Share
Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>