Setting up geokit.
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…
- sudo gem install geokit (if you haven’t already)
- script/plugin install git://github.com/andre/geokit-rails.git
- 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
3rails -v 2.3.5
pg
geokit --version '=1.5.0'
- get new developer keys for your heroku app
- http://developer.yahoo.com/maps/simple/
- http://code.google.com/apis/maps/signup.html
- add config.gem “geokit” to config/environment.rb
- edit your application controller file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20include 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.
Tags: