Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'gh-pages' of github.com:imajes/geokit into gh-pages

Conflicts:
	index.html
	params.json
  • Loading branch information...
commit 3c6ba5c254d0c37a298f477649a5141fce575311 2 parents 3ed52d0 + 3a47f42
@imajes imajes authored
Showing with 255 additions and 15 deletions.
  1. +254 −14 index.html
  2. +1 −1  params.json
View
268 index.html
@@ -38,32 +38,272 @@
<span class="credits right">Hosted on GitHub Pages &mdash; Theme by <a href="http://twitter.com/#!/michigangraham">mattgraham</a></span>
</div>
- <h3>Welcome to GitHub Pages.</h3>
+ <h2>GEOKIT GEM DESCRIPTION</h2>
-<p>This automatic page generator is the easiest way to create beautiful pages for all of your projects. Author your page content here using GitHub Flavored Markdown, select a template crafted by a designer, and publish. After your page is generated, you can check out the new branch:</p>
+<p>The Geokit gem provides:</p>
-<pre><code>$ cd your_repo_root/repo_name
-$ git fetch origin
-$ git checkout gh-pages
+<ul>
+<li>Distance calculations between two points on the earth. Calculate the distance in miles, kilometers, or nautical miles, with all the trigonometry abstracted away by GeoKit.</li>
+<li>Geocoding from multiple providers. It supports Google, Yahoo, Geocoder.us, and Geocoder.ca geocoders, and others. It provides a uniform response structure from all of them.
+It also provides a fail-over mechanism, in case your input fails to geocode in one service.</li>
+<li>Rectangular bounds calculations: is a point within a given rectangular bounds?</li>
+<li>Heading and midpoint calculations</li>
+</ul><p>Combine this gem with the <a href="http://github.com/imajes/geokit-rails">geokit-rails plugin</a> to get location-based finders for your Rails app.</p>
+
+<ul>
+<li>Geokit main site <a href="http://rubygeokit.org">http://rubygeokit.org/</a>.</li>
+<li>Repository at Github: <a href="http://github.com/imajes/geokit">http://github.com/imajes/geokit</a>.</li>
+<li>RDoc pages: <a href="http://rdoc.info/github/imajes/geokit/master/frames">http://rdoc.info/github/imajes/geokit/master/frames</a>
+</li>
+<li>Follow the Google Group for updates and discussion on Geokit: <a href="http://groups.google.com/group/geokit">http://groups.google.com/group/geokit</a>
+</li>
+</ul><h2>INSTALL</h2>
+
+<pre><code>gem install geokit
+</code></pre>
+
+<h2>QUICK START</h2>
+
+<pre><code>irb&gt; require 'rubygems'
+irb&gt; require 'geokit'
+irb&gt; a=Geokit::Geocoders::YahooGeocoder.geocode '140 Market St, San Francisco, CA'
+irb&gt; a.ll
+ =&gt; 37.79363,-122.396116
+irb&gt; b=Geokit::Geocoders::YahooGeocoder.geocode '789 Geary St, San Francisco, CA'
+irb&gt; b.ll
+ =&gt; 37.786217,-122.41619
+irb&gt; a.distance_to(b)
+ =&gt; 1.21120007413626
+irb&gt; a.heading_to(b)
+=&gt; 244.959832435678
+irb(main):006:0&gt; c=a.midpoint_to(b) # what's halfway from a to b?
+irb&gt; c.ll
+=&gt; "37.7899239257175,-122.406153503469"
+irb(main):008:0&gt; d=c.endpoint(90,10) # what's 10 miles to the east of c?
+irb&gt; d.ll
+=&gt; "37.7897825005142,-122.223214776155"
+</code></pre>
+
+<p>FYI, that <code>.ll</code> method means "latitude longitude".</p>
+
+<p>See the RDOC more more ... there are also operations on rectangular bounds (e.g., determining if a point is within bounds, find the center, etc).</p>
+
+<h2>CONFIGURATION</h2>
+
+<p>If you're using this gem by itself, here are the configuration options:</p>
+
+<pre><code># These defaults are used in Geokit::Mappable.distance_to and in acts_as_mappable
+Geokit::default_units = :miles
+Geokit::default_formula = :sphere
+
+# This is the timeout value in seconds to be used for calls to the geocoder web
+# services. For no timeout at all, comment out the setting. The timeout unit
+# is in seconds.
+Geokit::Geocoders::request_timeout = 3
+
+# These settings are used if web service calls must be routed through a proxy.
+# These setting can be nil if not needed, otherwise, addr and port must be
+# filled in at a minimum. If the proxy requires authentication, the username
+# and password can be provided as well.
+Geokit::Geocoders::proxy_addr = nil
+Geokit::Geocoders::proxy_port = nil
+Geokit::Geocoders::proxy_user = nil
+Geokit::Geocoders::proxy_pass = nil
+
+# This is your yahoo application key for the Yahoo Geocoder.
+# See http://developer.yahoo.com/faq/index.html#appid
+# and http://developer.yahoo.com/maps/rest/V1/geocode.html
+Geokit::Geocoders::yahoo = 'REPLACE_WITH_YOUR_YAHOO_KEY'
+
+# This is your Google Maps geocoder key.
+# See http://www.google.com/apis/maps/signup.html
+# and http://www.google.com/apis/maps/documentation/#Geocoding_Examples
+Geokit::Geocoders::google = 'REPLACE_WITH_YOUR_GOOGLE_KEY'
+
+# You can also set multiple API KEYS for different domains that may be directed to this same application.
+# The domain from which the current user is being directed will automatically be updated for Geokit via
+# the GeocoderControl class, which gets it's begin filter mixed into the ActionController.
+# You define these keys with a Hash as follows:
+#Geokit::Geocoders::google = { 'rubyonrails.org' =&gt; 'RUBY_ON_RAILS_API_KEY', 'ruby-docs.org' =&gt; 'RUBY_DOCS_API_KEY' }
+
+# This is your username and password for geocoder.us.
+# To use the free service, the value can be set to nil or false. For
+# usage tied to an account, the value should be set to username:password.
+# See http://geocoder.us
+# and http://geocoder.us/user/signup
+Geokit::Geocoders::geocoder_us = false
+
+# This is your authorization key for geocoder.ca.
+# To use the free service, the value can be set to nil or false. For
+# usage tied to an account, set the value to the key obtained from
+# Geocoder.ca.
+# See http://geocoder.ca
+# and http://geocoder.ca/?register=1
+Geokit::Geocoders::geocoder_ca = false
+
+# require "external_geocoder.rb"
+# Please see the section "writing your own geocoders" for more information.
+# Geokit::Geocoders::external_key = 'REPLACE_WITH_YOUR_API_KEY'
+
+# This is the order in which the geocoders are called in a failover scenario
+# If you only want to use a single geocoder, put a single symbol in the array.
+# Valid symbols are :google, :yahoo, :us, and :ca.
+# Be aware that there are Terms of Use restrictions on how you can use the
+# various geocoders. Make sure you read up on relevant Terms of Use for each
+# geocoder you are going to use.
+Geokit::Geocoders::provider_order = [:google,:us]
+
+# The IP provider order. Valid symbols are :ip,:geo_plugin.
+# As before, make sure you read up on relevant Terms of Use for each.
+# Geokit::Geocoders::ip_provider_order = [:external,:geo_plugin,:ip]
+</code></pre>
+
+<p>If you're using this gem with the <a href="http://github.com/imajes/geokit-rails">geokit-rails plugin</a>, the plugin
+creates a template with these settings and places it in <code>config/initializers/geokit_config.rb</code>.</p>
+
+<h2>SUPPORTED GEOCODERS</h2>
+
+<h3>"regular" address geocoders</h3>
+
+<ul>
+<li>Yahoo Geocoder - requires an API key.</li>
+<li>Geocoder.us - may require authentication if performing more than the free request limit.</li>
+<li>Geocoder.ca - for Canada; may require authentication as well.</li>
+<li>Geonames - a free geocoder</li>
+</ul><h3>address geocoders that also provide reverse geocoding</h3>
+
+<ul>
+<li>Google Geocoder - requires an API key. Also supports multiple results and bounding box/country code biasing.</li>
+</ul><h3>IP address geocoders</h3>
+
+<ul>
+<li>IP Geocoder - geocodes an IP address using hostip.info's web service.</li>
+<li>Geoplugin.net -- another IP address geocoder</li>
+</ul><h3>Google Geocoder Tricks</h3>
+
+<p>The Google Geocoder sports a number of useful tricks that elevate it a little bit above the rest of the currently supported geocoders. For starters, it returns a <code>suggested_bounds</code> property for all your geocoded results, so you can more easily decide where and how to center a map on the places you geocode. Here's a quick example:</p>
+
+<pre><code>irb&gt; res = Geokit::Geocoders::GoogleGeocoder.geocode('140 Market St, San Francisco, CA')
+irb&gt; pp res.suggested_bounds
+#&lt;Geokit::Bounds:0x53b36c
+ @ne=#&lt;Geokit::LatLng:0x53b204 @lat=37.7968528, @lng=-122.3926933&gt;,
+ @sw=#&lt;Geokit::LatLng:0x53b2b8 @lat=37.7905576, @lng=-122.3989885&gt;&gt;
</code></pre>
-<p>If you're using the GitHub for Mac, simply sync your repository and you'll see the new branch.</p>
+<p>In addition, you can use viewport or country code biasing to make sure the geocoders prefers results within a specific area. Say we wanted to geocode the city of Syracuse in Italy. A normal geocoding query would look like this:</p>
-<h3>Designer Templates</h3>
+<pre><code>irb&gt; res = Geokit::Geocoders::GoogleGeocoder.geocode('Syracuse')
+irb&gt; res.full_address
+=&gt; "Syracuse, NY, USA"
+</code></pre>
+
+<p>Not exactly what we were looking for. We know that Syracuse is in Italy, so we can tell the Google Geocoder to prefer results from Italy first, and then wander the Syracuses of the world. To do that, we have to pass Italy's ccTLD (country code top-level domain) to the <code>:bias</code> option of the <code>geocode</code> method. You can find a comprehensive list of all ccTLDs here: <a href="http://en.wikipedia.org/wiki/CcTLD">http://en.wikipedia.org/wiki/CcTLD</a>.</p>
+
+<pre><code>irb&gt; res = Geokit::Geocoders::GoogleGeocoder.geocode('Syracuse', :bias =&gt; 'it')
+irb&gt; res.full_address
+=&gt; "Syracuse, Italy"
+</code></pre>
+
+<p>Alternatively, we can speficy the geocoding bias as a bounding box object. Say we wanted to geocode the Winnetka district in Los Angeles.</p>
+
+<pre><code>irb&gt; res = Geokit::Geocoders::GoogleGeocoder.geocode('Winnetka')
+irb&gt; res.full_address
+=&gt; "Winnetka, IL, USA"
+</code></pre>
+
+<p>Not it. What we can do is tell the geocoder to return results only from in and around LA.</p>
+
+<pre><code>irb&gt; la_bounds = Geokit::Geocoders::GoogleGeocoder.geocode('Los Angeles').suggested_bounds
+irb&gt; res = Geokit::Geocoders::GoogleGeocoder.geocode('Winnetka', :bias =&gt; la_bounds)
+irb&gt; res.full_address
+=&gt; "Winnetka, California, USA"
+</code></pre>
+
+<h3>The Multigeocoder</h3>
+
+<p>Multi Geocoder - provides failover for the physical location geocoders, and also IP address geocoders. Its configured by setting Geokit::Geocoders::provider_order, and Geokit::Geocoders::ip_provider_order. You should call the Multi-Geocoder with its :geocode method, supplying one address parameter which is either a real street address, or an ip address. For example:</p>
+
+<pre><code>Geokit::Geocoders::MultiGeocoder.geocode("900 Sycamore Drive")
+
+Geokit::Geocoders::MultiGeocoder.geocode("12.12.12.12")
+</code></pre>
-<p>We've crafted some handsome templates for you to use. Go ahead and continue to layouts to browse through them. You can easily go back to edit your page before publishing. After publishing your page, you can revisit the page generator and switch to another theme. Your Page content will be preserved if it remained markdown format.</p>
+<h2>MULTIPLE RESULTS</h2>
-<h3>Rather Drive Stick?</h3>
+<p>Some geocoding services will return multple results if the there isn't one clear result.
+Geoloc can capture multiple results through its "all" method. Currently only the Google geocoder
+supports multiple results:</p>
-<p>If you prefer to not use the automatic generator, push a branch named <code>gh-pages</code> to your repository to create a page manually. In addition to supporting regular HTML content, GitHub Pages support Jekyll, a simple, blog aware static site generator written by our own Tom Preston-Werner. Jekyll makes it easy to create site-wide headers and footers without having to copy them across every page. It also offers intelligent blog support and other advanced templating features.</p>
+<pre><code>irb&gt; geo=Geokit::Geocoders::GoogleGeocoder.geocode("900 Sycamore Drive")
+irb&gt; geo.full_address
+=&gt; "900 Sycamore Dr, Arkadelphia, AR 71923, USA"
+irb&gt; geo.all.size
+irb&gt; geo.all.each { |e| puts e.full_address }
+900 Sycamore Dr, Arkadelphia, AR 71923, USA
+900 Sycamore Dr, Burkburnett, TX 76354, USA
+900 Sycamore Dr, TN 38361, USA
+....
+</code></pre>
+
+<p>geo.all is just an array of additional Geolocs, so do what you want with it. If you call .all on a
+geoloc that doesn't have any additional results, you will get an array of one.</p>
+
+<h2>NOTES ON WHAT'S WHERE</h2>
+
+<p>mappable.rb contains the Mappable module, which provides basic
+distance calculation methods, i.e., calculating the distance
+between two points.</p>
+
+<p>mappable.rb also contains LatLng, GeoLoc, and Bounds.
+LatLng is a simple container for latitude and longitude, but
+it's made more powerful by mixing in the above-mentioned Mappable
+module -- therefore, you can calculate easily the distance between two
+LatLng ojbects with <code>distance = first.distance_to(other)</code></p>
+
+<p>GeoLoc (also in mappable.rb) represents an address or location which
+has been geocoded. You can get the city, zipcode, street address, etc.
+from a GeoLoc object. GeoLoc extends LatLng, so you also get lat/lng
+AND the Mappable modeule goodness for free.</p>
+
+<p>geocoders.rb contains all the geocoder implemenations. All the gercoders
+inherit from a common base (class Geocoder) and implement the private method
+do_geocode.</p>
+
+<h2>WRITING YOUR OWN GEOCODERS</h2>
-<h3>Authors and Contributors</h3>
+<p>If you would like to write your own geocoders, you can do so by requiring 'geokit' or 'geokit/geocoders.rb' in a new file and subclassing the base class (which is class "Geocoder").
+You must then also require such extenal file back in your main geokit configuration.</p>
+
+<p>require "geokit"</p>
+
+<p>module Geokit
+ module Geocoders</p>
+
+<pre><code># Should be overriden as Geokit::Geocoders::external_key in your configuration file
+ @@external_key = 'REPLACE_WITH_YOUR_API_KEY'
+ __define_accessors
+
+# Replace name 'External' (below) with the name of your custom geocoder class
+# and use :external to specify this geocoder in your list of geocoders.
+ class ExternalGeocoder &lt; Geocoder
+ private
+ def self.do_geocode(address, options = {})
+ # Main geocoding method
+ end
+
+ def self.parse_http_resp(body) # :nodoc:
+ # Helper method to parse http response. See geokit/geocoders.rb.
+ end
+ end
+
+end
+</code></pre>
-<p>You can <a href="https://github.com/blog/821" class="user-mention">@mention</a> a GitHub username to generate a link to their profile. The resulting <code>&lt;a&gt;</code> element will link to the contributor's GitHub Profile. For example: In 2007, Chris Wanstrath (<a href="https://github.com/defunkt" class="user-mention">@defunkt</a>), PJ Hyett (<a href="https://github.com/pjhyett" class="user-mention">@pjhyett</a>), and Tom Preston-Werner (<a href="https://github.com/mojombo" class="user-mention">@mojombo</a>) founded GitHub.</p>
+<p>end</p>
-<h3>Support or Contact</h3>
+<h2>GOOGLE GROUP</h2>
-<p>Having trouble with Pages? Check out the documentation at <a href="http://help.github.com/pages">http://help.github.com/pages</a> or contact <a href="mailto:support@github.com">support@github.com</a> and we’ll help you sort it out.</p>
+<p>Follow the Google Group for updates and discussion on Geokit: <a href="http://groups.google.com/group/geokit">http://groups.google.com/group/geokit</a></p>
</section>
</div>
View
2  params.json
@@ -1 +1 @@
-{"name":"Geokit","body":"### Welcome to GitHub Pages.\r\nThis automatic page generator is the easiest way to create beautiful pages for all of your projects. Author your page content here using GitHub Flavored Markdown, select a template crafted by a designer, and publish. After your page is generated, you can check out the new branch:\r\n\r\n```\r\n$ cd your_repo_root/repo_name\r\n$ git fetch origin\r\n$ git checkout gh-pages\r\n```\r\n\r\nIf you're using the GitHub for Mac, simply sync your repository and you'll see the new branch.\r\n\r\n### Designer Templates\r\nWe've crafted some handsome templates for you to use. Go ahead and continue to layouts to browse through them. You can easily go back to edit your page before publishing. After publishing your page, you can revisit the page generator and switch to another theme. Your Page content will be preserved if it remained markdown format.\r\n\r\n### Rather Drive Stick?\r\nIf you prefer to not use the automatic generator, push a branch named `gh-pages` to your repository to create a page manually. In addition to supporting regular HTML content, GitHub Pages support Jekyll, a simple, blog aware static site generator written by our own Tom Preston-Werner. Jekyll makes it easy to create site-wide headers and footers without having to copy them across every page. It also offers intelligent blog support and other advanced templating features.\r\n\r\n### Authors and Contributors\r\nYou can @mention a GitHub username to generate a link to their profile. The resulting `<a>` element will link to the contributor's GitHub Profile. For example: In 2007, Chris Wanstrath (@defunkt), PJ Hyett (@pjhyett), and Tom Preston-Werner (@mojombo) founded GitHub.\r\n\r\n### Support or Contact\r\nHaving trouble with Pages? Check out the documentation at http://help.github.com/pages or contact support@github.com and we’ll help you sort it out.","tagline":"Official Geokit Gem. Geokit gem provides geocoding and distance/heading calculations. Pair with the geokit-rails plugin for full-fledged location-based app functionality.","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."}
+{"name":"Geokit","body":"## GEOKIT GEM DESCRIPTION\r\n\r\nThe Geokit gem provides:\r\n\r\n * Distance calculations between two points on the earth. Calculate the distance in miles, kilometers, or nautical miles, with all the trigonometry abstracted away by GeoKit.\r\n * Geocoding from multiple providers. It supports Google, Yahoo, Geocoder.us, and Geocoder.ca geocoders, and others. It provides a uniform response structure from all of them.\r\n It also provides a fail-over mechanism, in case your input fails to geocode in one service.\r\n * Rectangular bounds calculations: is a point within a given rectangular bounds?\r\n * Heading and midpoint calculations\r\n\r\nCombine this gem with the [geokit-rails plugin](http://github.com/imajes/geokit-rails) to get location-based finders for your Rails app.\r\n\r\n* Geokit main site [http://rubygeokit.org/](http://rubygeokit.org).\r\n* Repository at Github: [http://github.com/imajes/geokit](http://github.com/imajes/geokit).\r\n* RDoc pages: [http://rdoc.info/github/imajes/geokit/master/frames](http://rdoc.info/github/imajes/geokit/master/frames)\r\n* Follow the Google Group for updates and discussion on Geokit: [http://groups.google.com/group/geokit](http://groups.google.com/group/geokit)\r\n\r\n## INSTALL\r\n\r\n gem install geokit\r\n\r\n## QUICK START\r\n\r\n irb> require 'rubygems'\r\n irb> require 'geokit'\r\n irb> a=Geokit::Geocoders::YahooGeocoder.geocode '140 Market St, San Francisco, CA'\r\n irb> a.ll\r\n => 37.79363,-122.396116\r\n irb> b=Geokit::Geocoders::YahooGeocoder.geocode '789 Geary St, San Francisco, CA'\r\n irb> b.ll\r\n => 37.786217,-122.41619\r\n irb> a.distance_to(b)\r\n => 1.21120007413626\r\n irb> a.heading_to(b)\r\n => 244.959832435678\r\n irb(main):006:0> c=a.midpoint_to(b) # what's halfway from a to b?\r\n irb> c.ll\r\n => \"37.7899239257175,-122.406153503469\"\r\n irb(main):008:0> d=c.endpoint(90,10) # what's 10 miles to the east of c?\r\n irb> d.ll\r\n => \"37.7897825005142,-122.223214776155\"\r\n\r\nFYI, that `.ll` method means \"latitude longitude\".\r\n\r\nSee the RDOC more more ... there are also operations on rectangular bounds (e.g., determining if a point is within bounds, find the center, etc).\r\n\r\n## CONFIGURATION\r\n\r\nIf you're using this gem by itself, here are the configuration options:\r\n\r\n # These defaults are used in Geokit::Mappable.distance_to and in acts_as_mappable\r\n Geokit::default_units = :miles\r\n Geokit::default_formula = :sphere\r\n\r\n # This is the timeout value in seconds to be used for calls to the geocoder web\r\n # services. For no timeout at all, comment out the setting. The timeout unit\r\n # is in seconds.\r\n Geokit::Geocoders::request_timeout = 3\r\n\r\n # These settings are used if web service calls must be routed through a proxy.\r\n # These setting can be nil if not needed, otherwise, addr and port must be\r\n # filled in at a minimum. If the proxy requires authentication, the username\r\n # and password can be provided as well.\r\n Geokit::Geocoders::proxy_addr = nil\r\n Geokit::Geocoders::proxy_port = nil\r\n Geokit::Geocoders::proxy_user = nil\r\n Geokit::Geocoders::proxy_pass = nil\r\n\r\n # This is your yahoo application key for the Yahoo Geocoder.\r\n # See http://developer.yahoo.com/faq/index.html#appid\r\n # and http://developer.yahoo.com/maps/rest/V1/geocode.html\r\n Geokit::Geocoders::yahoo = 'REPLACE_WITH_YOUR_YAHOO_KEY'\r\n\r\n # This is your Google Maps geocoder key.\r\n # See http://www.google.com/apis/maps/signup.html\r\n # and http://www.google.com/apis/maps/documentation/#Geocoding_Examples\r\n Geokit::Geocoders::google = 'REPLACE_WITH_YOUR_GOOGLE_KEY'\r\n\r\n # You can also set multiple API KEYS for different domains that may be directed to this same application.\r\n # The domain from which the current user is being directed will automatically be updated for Geokit via\r\n # the GeocoderControl class, which gets it's begin filter mixed into the ActionController.\r\n # You define these keys with a Hash as follows:\r\n #Geokit::Geocoders::google = { 'rubyonrails.org' => 'RUBY_ON_RAILS_API_KEY', 'ruby-docs.org' => 'RUBY_DOCS_API_KEY' }\r\n\r\n # This is your username and password for geocoder.us.\r\n # To use the free service, the value can be set to nil or false. For\r\n # usage tied to an account, the value should be set to username:password.\r\n # See http://geocoder.us\r\n # and http://geocoder.us/user/signup\r\n Geokit::Geocoders::geocoder_us = false\r\n\r\n # This is your authorization key for geocoder.ca.\r\n # To use the free service, the value can be set to nil or false. For\r\n # usage tied to an account, set the value to the key obtained from\r\n # Geocoder.ca.\r\n # See http://geocoder.ca\r\n # and http://geocoder.ca/?register=1\r\n Geokit::Geocoders::geocoder_ca = false\r\n\r\n # require \"external_geocoder.rb\"\r\n # Please see the section \"writing your own geocoders\" for more information.\r\n # Geokit::Geocoders::external_key = 'REPLACE_WITH_YOUR_API_KEY'\r\n\r\n # This is the order in which the geocoders are called in a failover scenario\r\n # If you only want to use a single geocoder, put a single symbol in the array.\r\n # Valid symbols are :google, :yahoo, :us, and :ca.\r\n # Be aware that there are Terms of Use restrictions on how you can use the\r\n # various geocoders. Make sure you read up on relevant Terms of Use for each\r\n # geocoder you are going to use.\r\n Geokit::Geocoders::provider_order = [:google,:us]\r\n\r\n # The IP provider order. Valid symbols are :ip,:geo_plugin.\r\n # As before, make sure you read up on relevant Terms of Use for each.\r\n # Geokit::Geocoders::ip_provider_order = [:external,:geo_plugin,:ip]\r\n\r\nIf you're using this gem with the [geokit-rails plugin](http://github.com/imajes/geokit-rails), the plugin\r\ncreates a template with these settings and places it in `config/initializers/geokit_config.rb`.\r\n\r\n## SUPPORTED GEOCODERS\r\n\r\n### \"regular\" address geocoders\r\n* Yahoo Geocoder - requires an API key.\r\n* Geocoder.us - may require authentication if performing more than the free request limit.\r\n* Geocoder.ca - for Canada; may require authentication as well.\r\n* Geonames - a free geocoder\r\n\r\n### address geocoders that also provide reverse geocoding\r\n* Google Geocoder - requires an API key. Also supports multiple results and bounding box/country code biasing.\r\n\r\n### IP address geocoders\r\n* IP Geocoder - geocodes an IP address using hostip.info's web service.\r\n* Geoplugin.net -- another IP address geocoder\r\n\r\n### Google Geocoder Tricks\r\n\r\nThe Google Geocoder sports a number of useful tricks that elevate it a little bit above the rest of the currently supported geocoders. For starters, it returns a `suggested_bounds` property for all your geocoded results, so you can more easily decide where and how to center a map on the places you geocode. Here's a quick example:\r\n\r\n irb> res = Geokit::Geocoders::GoogleGeocoder.geocode('140 Market St, San Francisco, CA')\r\n irb> pp res.suggested_bounds\r\n #<Geokit::Bounds:0x53b36c\r\n @ne=#<Geokit::LatLng:0x53b204 @lat=37.7968528, @lng=-122.3926933>,\r\n @sw=#<Geokit::LatLng:0x53b2b8 @lat=37.7905576, @lng=-122.3989885>>\r\n\r\nIn addition, you can use viewport or country code biasing to make sure the geocoders prefers results within a specific area. Say we wanted to geocode the city of Syracuse in Italy. A normal geocoding query would look like this:\r\n\r\n irb> res = Geokit::Geocoders::GoogleGeocoder.geocode('Syracuse')\r\n irb> res.full_address\r\n => \"Syracuse, NY, USA\"\r\n\r\nNot exactly what we were looking for. We know that Syracuse is in Italy, so we can tell the Google Geocoder to prefer results from Italy first, and then wander the Syracuses of the world. To do that, we have to pass Italy's ccTLD (country code top-level domain) to the `:bias` option of the `geocode` method. You can find a comprehensive list of all ccTLDs here: http://en.wikipedia.org/wiki/CcTLD.\r\n\r\n irb> res = Geokit::Geocoders::GoogleGeocoder.geocode('Syracuse', :bias => 'it')\r\n irb> res.full_address\r\n => \"Syracuse, Italy\"\r\n\r\nAlternatively, we can speficy the geocoding bias as a bounding box object. Say we wanted to geocode the Winnetka district in Los Angeles.\r\n\r\n irb> res = Geokit::Geocoders::GoogleGeocoder.geocode('Winnetka')\r\n irb> res.full_address\r\n => \"Winnetka, IL, USA\"\r\n\r\nNot it. What we can do is tell the geocoder to return results only from in and around LA.\r\n\r\n irb> la_bounds = Geokit::Geocoders::GoogleGeocoder.geocode('Los Angeles').suggested_bounds\r\n irb> res = Geokit::Geocoders::GoogleGeocoder.geocode('Winnetka', :bias => la_bounds)\r\n irb> res.full_address\r\n => \"Winnetka, California, USA\"\r\n\r\n\r\n### The Multigeocoder\r\nMulti Geocoder - provides failover for the physical location geocoders, and also IP address geocoders. Its configured by setting Geokit::Geocoders::provider_order, and Geokit::Geocoders::ip_provider_order. You should call the Multi-Geocoder with its :geocode method, supplying one address parameter which is either a real street address, or an ip address. For example:\r\n\r\n Geokit::Geocoders::MultiGeocoder.geocode(\"900 Sycamore Drive\")\r\n\r\n Geokit::Geocoders::MultiGeocoder.geocode(\"12.12.12.12\")\r\n\r\n## MULTIPLE RESULTS\r\nSome geocoding services will return multple results if the there isn't one clear result.\r\nGeoloc can capture multiple results through its \"all\" method. Currently only the Google geocoder\r\nsupports multiple results:\r\n\r\n irb> geo=Geokit::Geocoders::GoogleGeocoder.geocode(\"900 Sycamore Drive\")\r\n irb> geo.full_address\r\n => \"900 Sycamore Dr, Arkadelphia, AR 71923, USA\"\r\n irb> geo.all.size\r\n irb> geo.all.each { |e| puts e.full_address }\r\n 900 Sycamore Dr, Arkadelphia, AR 71923, USA\r\n 900 Sycamore Dr, Burkburnett, TX 76354, USA\r\n 900 Sycamore Dr, TN 38361, USA\r\n ....\r\n\r\ngeo.all is just an array of additional Geolocs, so do what you want with it. If you call .all on a\r\ngeoloc that doesn't have any additional results, you will get an array of one.\r\n\r\n\r\n## NOTES ON WHAT'S WHERE\r\n\r\nmappable.rb contains the Mappable module, which provides basic\r\ndistance calculation methods, i.e., calculating the distance\r\nbetween two points.\r\n\r\nmappable.rb also contains LatLng, GeoLoc, and Bounds.\r\nLatLng is a simple container for latitude and longitude, but\r\nit's made more powerful by mixing in the above-mentioned Mappable\r\nmodule -- therefore, you can calculate easily the distance between two\r\nLatLng ojbects with `distance = first.distance_to(other)`\r\n\r\nGeoLoc (also in mappable.rb) represents an address or location which\r\nhas been geocoded. You can get the city, zipcode, street address, etc.\r\nfrom a GeoLoc object. GeoLoc extends LatLng, so you also get lat/lng\r\nAND the Mappable modeule goodness for free.\r\n\r\ngeocoders.rb contains all the geocoder implemenations. All the gercoders\r\ninherit from a common base (class Geocoder) and implement the private method\r\ndo_geocode.\r\n\r\n## WRITING YOUR OWN GEOCODERS\r\n\r\nIf you would like to write your own geocoders, you can do so by requiring 'geokit' or 'geokit/geocoders.rb' in a new file and subclassing the base class (which is class \"Geocoder\").\r\nYou must then also require such extenal file back in your main geokit configuration.\r\n\r\n require \"geokit\"\r\n\r\n module Geokit\r\n module Geocoders\r\n\r\n # Should be overriden as Geokit::Geocoders::external_key in your configuration file\r\n @@external_key = 'REPLACE_WITH_YOUR_API_KEY'\r\n __define_accessors\r\n\r\n # Replace name 'External' (below) with the name of your custom geocoder class\r\n # and use :external to specify this geocoder in your list of geocoders.\r\n class ExternalGeocoder < Geocoder\r\n private\r\n def self.do_geocode(address, options = {})\r\n # Main geocoding method\r\n end\r\n\r\n def self.parse_http_resp(body) # :nodoc:\r\n # Helper method to parse http response. See geokit/geocoders.rb.\r\n end\r\n end\r\n\r\n end\r\n end\r\n\r\n## GOOGLE GROUP\r\n\r\nFollow the Google Group for updates and discussion on Geokit: http://groups.google.com/group/geokit\r\n\r\n","tagline":"Official Geokit Gem. Geokit gem provides geocoding and distance/heading calculations. Pair with the geokit-rails plugin for full-fledged location-based app functionality.","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."}
Please sign in to comment.
Something went wrong with that request. Please try again.