SlideShare a Scribd company logo
1 of 36
Download to read offline
Geokit
in
social
apps
What
is
Geokit?

๏ A
RubyGem
and
Rails
plugin
๏ A
wrapper
to
various
geocoding
providers
๏ Supports
geocoding
addresses,
lat/lng

  coordinates,
and
IP
Addresses
What
is
Geokit?

๏ Provides
distance,
heading,
and
midpoint

  calcula>ons
between
two
points
๏ Provides
rectangular
bounds
calcula>on;

  reveal
if
a
point
is
within
bounds
The
guts
of
the
gem
    Geokit

                 Contains class and instance
    Mappable     methods providing distance
                    calculation services




                Contains customised instance
    Inflector   methods to extend the Inflector
                          module




               Contains class methods wrapping
   Geocoders         geocoding services
The
guts
of
the
gem
           Geocoders
      GeocodeError < StandardError

               Geocoder

              CaGeocoder

              UsGeocoder

            YahooGeocoder

           GeonamesGeocoder

            GoogleGeocoder

           GeoPluginGeocoder

              IpGeocoder

             MultiGeocoder
The
guts
of
the
gem
       Mappable
        ClassMethods


           LatLng

          GeoLoc



          Bounds
Geocoding
an
address

 sudo gem install geokit

 irb

 > require ‘rubygems’

 > require ‘geokit’
Geocoding
an
address
 > a=Geokit::Geocoders::YahooGeocoder.geocode('45
 Balls Pond Road, London, UK')

 => <Geokit::GeoLoc:0x19105cc
 @all=[#<Geokit::GeoLoc:0x19105cc ...>],
 @lat=51.546004, @precision=quot;addressquot;,
 @state=quot;United Kingdomquot;, @success=true,
 @city=quot;Hoxton, N1 4quot;, @country_code=quot;GBquot;,
 @provider=quot;yahooquot;, @street_address=quot;45 Balls Pond
 Roadquot;, @lng=-0.077033, @full_address=nil, @zip=nil>

 > a.ll

 => quot;51.546004,-0.077033quot;
Reverse
Geocoding
> b=
Geokit::Geocoders::GoogleGeocoder.geocode(a.ll)

(output skipped)

> b.all.map{|obj| puts obj.full_address}

=> 28-30 Bentley Rd, Hackney, Greater London, UK
Islington, Greater London N1 4, UK
Hackney, Greater London, UK
Hackney, Greater London, UK
Greater London, UK
England, United Kingdom
United Kingdom
IP
Address
Geocoding

 > cia_dot_gov =
 Geokit::Geocoders::GeoPluginGeocoder.geocode('198.8
 1.129.100')

 => #<Geokit::GeoLoc:0x18160e0
 @all=[#<Geokit::GeoLoc:0x18160e0 ...>],
 @lat=38.957901, @precision=quot;unknownquot;, @state=quot;VAquot;,
 @success=true, @city=quot;Restonquot;, @country_code=quot;USquot;,
 @provider=quot;geoPluginquot;, @street_address=nil,
 @lng=-77.343903, @full_address=nil, @zip=nil>
Rails
plugin
magic

• The
rails
plugin
can
automa>cally
geocode

  new
Ac>veRecord
records
upon
crea>on

• It
can
geocode
your
ip
address
in
the

  controller
and
store
the
result
in
the

  session.
Hippo
Hippo

• A
rails
applica>on
built
using
Michael

  Bleigh’s
excellent
TwiHerAuth
rails

  template.

• Let’s
geocode
the
logged‐in
user’s
loca>on

  upon
them
logging
in
to
the
applica>on
Auto‐geocode
model



 class User < TwitterAuth::GenericUser
   acts_as_mappable :auto_geocode => {:field => :location}
   before_validation_on_update :auto_geocode_address, :if
   => :location_changed?
 end
Ge?ng
a
loca@on
from

   an
ip
address

• Maybe
your
users
don’t
login
to
your

  applica>on,
or
provide
an
address
to

  geocode,
what
do
you
do
then?
Ge?ng
a
loca@on
from

   an
ip
address

• You
can
use
a
1
line
method
in
your

  controller
to
geocode
your
user’s
ip
address

  and
get
a
city‐level
accurate
loca>on
for

  your
user.

Ge?ng
a
loca@on
from

   an
ip
address


  class StaticController < ApplicationController
    geocode_ip_address
  end
So
you
know
where
I

         am...
• ...but
maybe
that’s
not
what
your

  applica>on
cares
about.

• What
if
you
have
an
applica>on
that
has

  lots
of
records
with
addresses
aHached
to

  them,
and
you’d
like
to
make
those
records

  searchable
by
their
loca>on?
Ac@ve
Record
finders
• Geokit
gives
you
a
collec>on
of

  Ac>veRecord‐style
finders
that
can:

  • auto‐geocode
the
input
loca>on
  • find
records
within
a
given
range
  • order
results
by
their
distance
from
the

    address
Ac@ve
Record
finders

 class CafeController < ApplicationController

   def search
     @query = params[:query]
     @range = params[:range]
        Cafe.find_within(@range, :origin => @query, :order =>
    ‘distance’)
   end

 end
What
does
Geokit
do?


๏ Provides
distance,
heading,
and
midpoint

  calcula>ons
between
two
points
๏ Provides
rectangular
bounds
calcula>on;

  reveal
if
a
point
is
within
bounds
Distance
Calcula@on

> london =
Geokit::Geocoders::GoogleGeocoder.geocode('London')

=> #<Geokit::GeoLoc:0x17d1c88
@all=[#<Geokit::GeoLoc:0x17d1c88 ...>],
@lat=51.5001524, @precision=quot;cityquot;, @state=quot;Greater
Londonquot;, @success=true, @city=quot;Londonquot;,
@country_code=quot;GBquot;, @provider=quot;googlequot;,
@street_address=nil, @lng=-0.1262362,
@full_address=quot;Westminster, London, UKquot;, @zip=nil>
Distance
Calcula@on

> new_york =
Geokit::Geocoders::GoogleGeocoder.geocode('New
York')

=> #<Geokit::GeoLoc:0x182d510
@all=[#<Geokit::GeoLoc:0x182d510 ...>],
@lat=40.756054, @precision=quot;cityquot;, @state=quot;NYquot;,
@success=true, @city=quot;New Yorkquot;,
@country_code=quot;USquot;, @provider=quot;googlequot;,
@street_address=nil, @lng=-73.986951,
@full_address=quot;New York, NY, USAquot;, @zip=nil>
Distance
Calcula@on

>london.distance_from(
new_york, :units
=> :miles)

=> 3462.62226994318

>london.distance_from(
new_york, :formula
=> :flat)

=> 2748.37417609529
Heading
Calcula@on

>london.heading_from(
new_york)

=> 51.254276626762

>london.heading_to(
new_york)

=> 288.368616560178
Midpoint
Calcula@on

>
london.midpoint_to(new
_york)

=> #<Geokit::LatLng:
0x1789960
@lat=52.3833438845311,
@lng=-41.2615007683062
>
Endpoint
Calcula@on

> london.endpoint(340,
50)

=> #<Geokit::LatLng:
0x18385f0
@lat=52.1787256392731,
@lng=-0.5294069905067>
Within
Bounds
> south_west =
Geokit::Geocoders::GoogleGeocoder.geocode('Bristol,
UK')

                 (output skipped)

> north_east =
Geokit::Geocoders::GoogleGeocoder.geocode('Hull,
UK')

                 (output skipped)
Within
Bounds

> bounds = Geokit::Bounds.new(south_west,
north_east)

                 (output skipped)

> midlands =
Geokit::Geocoders::GoogleGeocoder.geocode('Nottingh
am, UK')

                 (output skipped)
Within
Bounds

> bounds.contains?
(midlands)

=> true

> bounds.center

=> #<Geokit::LatLng:
0x1708090
@lat=52.6051976419128,
@lng=-1.49169672003523
>
Limita@ons

• Geokit’s
Rails
plugin
does
not
work
with:
 • SQLite
 • PostgreSQL
(versions
below
8.1)
Ruby
1.9?
√   YES
Alterna@ves

• Gra>cule
(hHp://gra>cule.rubyforge.org)
• YM4R
(hHp://ym4r.rubyforge.org)
• Geocoder
(hHp://geocoder.rubyforge.org/)
A
useful
resource
• Beginning
Google
Maps
Applica>ons
with

  Rails
and
Ajax:
From
Novice
to
Professional

 • Part‐wriHen
by
Andre
Lewis
(co‐author
of

    Geokit)

 • Contains
a
wealth
of
informa>on
about

    geocoding
Thanks




Paul
Jensen
New
Bamboo

paul@new‐bamboo.co.uk
@paulbjensen

More Related Content

Viewers also liked

Mimic Me General Information English
Mimic Me General Information EnglishMimic Me General Information English
Mimic Me General Information English
corne3d
 
Lesson 14 vocab
Lesson 14 vocabLesson 14 vocab
Lesson 14 vocab
PEDH
 
Stockholm Presentation To Wsp Council On Results Of Iys 19 August09
Stockholm Presentation To Wsp Council On Results Of Iys 19 August09Stockholm Presentation To Wsp Council On Results Of Iys 19 August09
Stockholm Presentation To Wsp Council On Results Of Iys 19 August09
Yehude Simon Valcárcel
 
Rashmi Sinha
Rashmi SinhaRashmi Sinha
Rashmi Sinha
tieadmin
 

Viewers also liked (15)

What's Next? Chatham-Siler City Advanced Manufacturing Site
What's Next? Chatham-Siler City Advanced Manufacturing SiteWhat's Next? Chatham-Siler City Advanced Manufacturing Site
What's Next? Chatham-Siler City Advanced Manufacturing Site
 
Listening for Opps on Twitter
Listening for Opps on TwitterListening for Opps on Twitter
Listening for Opps on Twitter
 
Mimic Me General Information English
Mimic Me General Information EnglishMimic Me General Information English
Mimic Me General Information English
 
Lesson 14 vocab
Lesson 14 vocabLesson 14 vocab
Lesson 14 vocab
 
D for digital
D for digitalD for digital
D for digital
 
Shari Gunn
Shari GunnShari Gunn
Shari Gunn
 
A Christmas Story
A Christmas StoryA Christmas Story
A Christmas Story
 
Stockholm Presentation To Wsp Council On Results Of Iys 19 August09
Stockholm Presentation To Wsp Council On Results Of Iys 19 August09Stockholm Presentation To Wsp Council On Results Of Iys 19 August09
Stockholm Presentation To Wsp Council On Results Of Iys 19 August09
 
Viva La Revolution: Why Universal Banking is under siege and what needs to be...
Viva La Revolution: Why Universal Banking is under siege and what needs to be...Viva La Revolution: Why Universal Banking is under siege and what needs to be...
Viva La Revolution: Why Universal Banking is under siege and what needs to be...
 
What Bank's can learn from the Fab Four
What Bank's can learn from the Fab FourWhat Bank's can learn from the Fab Four
What Bank's can learn from the Fab Four
 
Rashmi Sinha
Rashmi SinhaRashmi Sinha
Rashmi Sinha
 
Hak cipta dan fair use
Hak cipta dan fair useHak cipta dan fair use
Hak cipta dan fair use
 
Online Video Marketing course
Online Video Marketing courseOnline Video Marketing course
Online Video Marketing course
 
USMEP Presentation
USMEP PresentationUSMEP Presentation
USMEP Presentation
 
Visual Thinking for Islamic Education
Visual Thinking for Islamic EducationVisual Thinking for Islamic Education
Visual Thinking for Islamic Education
 

Similar to Geokit In Social Apps

Google MAP API
Google MAP APIGoogle MAP API
Google MAP API
Eric Lee
 
Barcamp GoogleMaps - praktické ukázky kódu
Barcamp GoogleMaps - praktické ukázky kóduBarcamp GoogleMaps - praktické ukázky kódu
Barcamp GoogleMaps - praktické ukázky kódu
Milos Lenoch
 
Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...
Matteo Collina
 
Cameroun - Repertoire des projets prioritaires à besoins de financement
Cameroun - Repertoire des projets prioritaires à besoins de financementCameroun - Repertoire des projets prioritaires à besoins de financement
Cameroun - Repertoire des projets prioritaires à besoins de financement
investincameroon
 

Similar to Geokit In Social Apps (20)

Google MAP API
Google MAP APIGoogle MAP API
Google MAP API
 
Rails GIS Hacks
Rails GIS HacksRails GIS Hacks
Rails GIS Hacks
 
Gmaps Railscamp2008
Gmaps Railscamp2008Gmaps Railscamp2008
Gmaps Railscamp2008
 
Where20 2008 Ruby Tutorial
Where20 2008 Ruby TutorialWhere20 2008 Ruby Tutorial
Where20 2008 Ruby Tutorial
 
GeoScript - Spatial Capabilities for Scripting Languages
GeoScript - Spatial Capabilities for Scripting LanguagesGeoScript - Spatial Capabilities for Scripting Languages
GeoScript - Spatial Capabilities for Scripting Languages
 
Remote Geocoding
Remote GeocodingRemote Geocoding
Remote Geocoding
 
Rails Gis Hacks
Rails Gis HacksRails Gis Hacks
Rails Gis Hacks
 
Google maps
Google mapsGoogle maps
Google maps
 
Google maps
Google mapsGoogle maps
Google maps
 
Mansour Raad & Anthony Jayaprakash - Yet Another Mapping Framework, NOT!
Mansour Raad & Anthony Jayaprakash - Yet Another Mapping Framework, NOT!Mansour Raad & Anthony Jayaprakash - Yet Another Mapping Framework, NOT!
Mansour Raad & Anthony Jayaprakash - Yet Another Mapping Framework, NOT!
 
Barcamp GoogleMaps - praktické ukázky kódu
Barcamp GoogleMaps - praktické ukázky kóduBarcamp GoogleMaps - praktické ukázky kódu
Barcamp GoogleMaps - praktické ukázky kódu
 
Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...Designing and developing mobile web applications with Mockup, Sencha Touch an...
Designing and developing mobile web applications with Mockup, Sencha Touch an...
 
Where 2.0
Where 2.0Where 2.0
Where 2.0
 
Rocky Mountain URISA Talk (June 2008)
Rocky Mountain URISA Talk (June 2008)Rocky Mountain URISA Talk (June 2008)
Rocky Mountain URISA Talk (June 2008)
 
Clase de Macroeconomía del 12.05.21
Clase de Macroeconomía del 12.05.21 Clase de Macroeconomía del 12.05.21
Clase de Macroeconomía del 12.05.21
 
Most Recent Samples
Most Recent SamplesMost Recent Samples
Most Recent Samples
 
Python And GIS - Beyond Modelbuilder And Pythonwin
Python And GIS - Beyond Modelbuilder And PythonwinPython And GIS - Beyond Modelbuilder And Pythonwin
Python And GIS - Beyond Modelbuilder And Pythonwin
 
Cameroun - Repertoire des projets prioritaires à besoins de financement
Cameroun - Repertoire des projets prioritaires à besoins de financementCameroun - Repertoire des projets prioritaires à besoins de financement
Cameroun - Repertoire des projets prioritaires à besoins de financement
 
Google. Мобильная реклама сегодня
Google. Мобильная реклама сегодняGoogle. Мобильная реклама сегодня
Google. Мобильная реклама сегодня
 
JavaOne 2009 - 2d Vector Graphics in the browser with Canvas and SVG
JavaOne 2009 -  2d Vector Graphics in the browser with Canvas and SVGJavaOne 2009 -  2d Vector Graphics in the browser with Canvas and SVG
JavaOne 2009 - 2d Vector Graphics in the browser with Canvas and SVG
 

More from Paul Jensen (6)

End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
 
Objection.js, a SQL ORM
Objection.js, a SQL ORMObjection.js, a SQL ORM
Objection.js, a SQL ORM
 
E2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
E2E testing Single Page Apps and APIs with Cucumber.js and PuppeteerE2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
E2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
 
Lnug jan 2018
Lnug jan 2018Lnug jan 2018
Lnug jan 2018
 
Desktop apps with node webkit
Desktop apps with node webkitDesktop apps with node webkit
Desktop apps with node webkit
 
SocketStream
SocketStreamSocketStream
SocketStream
 

Recently uploaded

Recently uploaded (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

Geokit In Social Apps