What is GeoKit?
Geokit is a Rails plugin for building location-based apps. It provides geocoding, location finders, and distance calculation in one cohesive package. If you have any tables with latitude/longitude oolumns in your database, or if you every wanted to easily query for "all the stores within a 50 mile radius," then GeoKit is for you.
What can GeoKit do for you?
- Distance calculations between two points on the earth. Calculate the distance in miles or KM, with all the trigonometry abstracted away by GeoKit.
- ActiveRecord distance-based finders. For example, you can find all the points in your database within a 50-mile radius.
- Geocoding from multiple providers. It currently supports Google, Yahoo, Geocoder.us, and Geocoder.ca geocoders, and 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.
- IP-based location lookup utilizing hostip.info. Provide an IP address, and get city name and latitude/longitude in return.
- A before_filter helper to geocode the user's location based on IP address, and retain the location in a cookie.
Find near latitude and longitude:
Store.find(:all, :origin => [37.792, -122.393] :conditions=>'distance<10')
Find near an address:
Store.find(:all, :origin=>'100 Spear st, San Francisco, CA', :conditions=>'distance<10')
Geocode an address:
res=GeoKit::Geocoders::GoogleGeocoder.geocode('100 Spear st, San Francisco, CA') puts res.lat
Where can you get it?
Head over to GeoKit at RubyForge for the plugin source and API docs.
Or, skip right to installing it as a plugin:
ruby script/plugin install svn://rubyforge.org/var/svn/geokit/trunk