New GeoKit Release
I committed some major improvements to GeoKit recently. Head over to GeoKit at Rubyforge for an updated readme and API. Here is a rundown of the improvements. As always, install with:
sudo script/plugin install svn://rubyforge.org/var/svn/geokit/trunk
New Functionality
- auto geocoding: an option to automatically geocode a model's address field on create
- in-memory sort-by-distance for arrays of location objects
- bounding box queries:
Location.find :all, :bounds=>[sw,ne] - improved performance by automatically adding a bounding box condition to radial queries
- new Bounds class for in-memory bounds-related operations
- ability to calculate heading and midpoint between two points
- ability to calculate endpoint given a point, heading, and distance
Auto Geocoding
If your geocoding needs are simple, you can tell your model to automatically geocode itself on create:
class Store < ActiveRecord::Base
acts_as_mappable :auto_geocode=>true
end
It takes two optional params:
class Store < ActiveRecord::Base
acts_as_mappable :auto_geocode=>{:field=>:address, :error_message=>'Could not geocode address'}
end
. . . which is equivalent to:
class Store << ActiveRecord::Base
acts_as_mappable
before_validation_on_create :geocode_address
private
def geocode_address
geo=GeoKit::Geocoders::MultiGeocoder.geocode (address)
errors.add(:address, "Could not Geocode address") if !geo.success
self.lat, self.lng = geo.lat,geo.lng if geo.success
end
end
If you need any more complicated geocoding behavior for your model, you should roll your own before_validate callback.
In-memory sort-by-distance for arrays of location objects
Usually, you can do your sorting in the database as part of your find call. If you need to sort things post-query, you can do so:
stores=Store.find :all
stores.sort_by_distance_from(home)
puts stores.first.distance
Obviously, each of the items in the array must have a latitude/longitude so they can be sorted by distance.
You may need to do this when you use :include. You can use includes along with your distance finders:
stores=Store.find :all, :origin=>home, :include=>[:reviews,:cities] :within=>5, :order=>'distance'
However, ActiveRecord drops the calculated distance column when you use include. So, if you need to use the distance column, you'll have to re-calculate it post-query in Ruby:
stores.sort_by_distance_from(home)
The in-memory distance calcs are probably slower than the DB, but at least you can get them if you really need to. It's certainly tolerable on a small result set.
Bounding boxes
There is a new class, GeoKit::Bounds
bounds=GeoKit::Bounds.new(sq_sw_point,ne_point)
or, if you need to created it from a point and radius:
bounds=GeoKit::Bounds.from_point_and_radius(home,5)
If you are displaying points on a map, you probably need to query for whatever falls within the rectangular bounds of the map:
Shop.find :all, :bounds=>[sw_point,ne_point]
or, if you already have a Bounds instance:
Shop.find :all, :bounds=>bounds
The input to :bounds can be array with the two points or a Bounds object. However you provide them, the order should always be the southwest corner, northeast corner of the rectangle. Typically, you will be getting the swpoint and nepoint from a map that is displayed on a web page.
You can also find the center of a box, and determine if an individual point is inside a box. See the API for details.
Performance Improvement w/radial queries
When you do a radial query (Shop.find :all, :origin=>home, :within=>5), GeoKit will automatically create a bounding box around the circle to improve performance. It will only apply the bounding box if you don't provide a bounding box yourself.
Distances, headings, endpoints, and midpoints
distance=home.distance_from(work, :units=>:miles)
heading=home.heading_to(work) # result is in degrees, 0 is north
endpoint=home.endpoint(90,2) # two miles due east
midpoing=home.midpoint_to(work)
Bug Fixes
1) fixed problem when :including another model which also has lat lat/lng columns. Previously, a query like this wouldn't work.
2) added logic to support :include together with :order. Whenever you use :include, ActiveRecord drops the 'distance' pseudo-column from the select, which means that the :order clause couldn't reference it. I added logic to replace the reference to the literal "distance" column in the order clause with the distance_sql only when you are also using an :include. This keeps it from bombing when you use :include and :order together.

Comments
Enrico on Jul 30
When I go to google maps and I input a partial address, I get a 'did you mean' search result left nav that allows me to pick which address I meant.
Does Google or geoKit support retrieving the list of possible matches to the partial address query (an array of GeoLoc objects) ?
Andre Lewis on Jul 30
Enrico, right now GeoKit doesn't support multiple geocoding results. I plan on adding it in at some point when I have time.
Alex K on Jul 30
Hi Andre,
I noticed when sending in a long/lat for the find method (using :within and :origin), it still goes out and geocodes it for me. I was just wondering if that was intentional or not - as I want to avoid the geocoding on the search if I know the long/lat.
Alex Kira on Jul 30
Hi Andre,
Ignore the last comment - that was my mistake.. I was converting it to string somewhere, thought I had checked that but I missed it somewhere..
Steve on Jul 30
Is there a reason that it does nothing when I try to install the geokit plugin? I don't get an error or anything, just nothing happens.
I then tried to download the zip from rubyforge and it's not there. Is this plugin still available or did something happen and I missed the boat?
Andre Lewis on Jul 30
Steve -- try again with script/plugin install. Rubyforge is kind of unreliable sometimes. I just tried it and it installed fine.
Steve on Jul 30
That's what I've been trying. I type in:
ruby script/plugin install svn://rubyforge.org/var/svn/geokit/trunk
and nothing happens. It just goes to the command line again. I just tried using the same command to install the acts_as_geocodable plugin and it worked fine. I'm extremely new to rails (a couple weeks), so I have no idea what's going on.
Tyler on Aug 01
I am getting the same issue on both my windows machines with the install - just nothing happens.
I'm using: script/plugin install svn://rubyforge.org/var/svn/geokit/trunk
other plugins will install fine, is there another place to get the plugin?
I'm using ruby 1.8.6 and rails 1.2.3 on 32 and 64 bit machines.
Joel Nylund on Aug 01
Hi, this is the very coolest plugin, I got it working very quickly in the console, using it to calc distance between 2 zip codes. The only issue is once I load it into my rails app, some very weird stuff starts to happen. ActiveRecord gets really confused (it thinks some models dont have values that im sure they do, then I start getting weird messges when I doa redirect in the browser that say "You are being Redirected", then finally the server will not stop gracefully.
I see these error in my mongrel log files:
Wed Aug 01 18:56:22 EDT 2007: Error calling Dispatcher.dispatch #
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:422:in `remove_const'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:422:in `remove_constant'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:273:in `remove_unloadable_constants!'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:273:in `remove_unloadable_constants!'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:72:in `clear'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:60:in `reset_application!'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:116:in `reset_after_dispatch'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:51:in `dispatch'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/rails.rb:84:in `process'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/1.8/sync.rb:229:in `synchronize'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/rails.rb:83:in `process'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:580:in `process_client'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:579:in `process_client'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:686:in `run'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:686:in `run'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:673:in `run'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/configurator.rb:267:in `run'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/configurator.rb:266:in `run'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/bin/mongrel_rails:127:in `run'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/command.rb:211:in `run'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/bin/mongrel_rails:231
Am I using the wrong version of rails, is there a smaller version of the stuff that just doesn distance calculation without messing with activerecord?
thanks
joel
Andre Lewis on Aug 01
Steve, Tyler: your machine is having trouble with the svn:// protocol -- if you try installing another plugin off of rubyforge with an svn:// location, you'll encounter the same thing. I'm not sure what the answer is -- try googling around for "windows svn" perhaps.
Joel: I haven't heard any reports of GeoKit causing this kind of problem. If you want to keep GeoKit from mixing-in to ActiveRecord, remove the last two lines from GeoKit's init.rb -- this is where GeoKit adds functionality to AR.
Tyler on Aug 02
For reference I figured out the install problem on windows. You need to download and install subversion for windows. After you install open a command prompt and cd to your rails app then type:
svnadmin create /myRailsApp/svn
This will give you subversion functionality but more importantly you can install the GeoKit plugin! I also had the same problem trying to install the ZiYa Charting the Rails plugin but it installs correctly to the vendor/plugins directory too.
I've been using rails on a daily basis since April07 and haven't run into this problem til now so I hope this helps the beginners out there.
A good subversion reference can be found at red-bean.com
Andre Lewis on Aug 06
Tyler -- thanks for helping out windows folks with the solution! Do you actually have to create a local svn repository though, or just have subversion installed? In any case, thanks for posting.
Cheers,
Andre
Tyler on Aug 06
Andre,
You must create a SVN repository. The plugin will not install just by installing SVN. Once you create the SVN repository in the app structure the plugin will successfully install.
I just tested your question out on my personal laptop(win32 Vista) and it did not work.
I got the plugin up on my dev machine(win32 XP) and production server(64 bit Server 2003) last week and on my laptop today after I installed SVN and created the repository.
Tyler
dudz.josh on Aug 08
Hey I'm not sure where to submit a patch but with a change to edge rails I had an error.
I have a fix though.
Fix In acts_as_mappable.rb
This
options = extract_options_from_args!(args)
to
options = args.extract_options!
Cheers for the great plugin.
Kevin Elliott on Aug 09
Andre,
Excellent plugin. I've been using it for about 6 months, and I was very pleased to see a new release! Especially once that fixes those pesky :include bugs...
My current project using GeoKit is setup a little strangely and is causing a couple of problems using GeoKit. There is a primary model, and then a belongs_to to an Address model. Therefore, I can not run distance_from() methods on the primary models.
For example, let's say the primary model was named Business, which belongs_to Address. Typically, I have to search for nearby Businesses with:
@nearby_businesses = Address.find(
:all,
:origin => @business.address.to_s,
:include => [:business],
:limit => 10,
:conditions => ['distance ).map { |add| add.business }
This seems to work fine if I just want to find businesses near another business. However, if I want to get the distance from the reference business to each of the nearby businesses, this presents a problem.
I can't seem to get these distances. Could you help?
Thanks,
Kevin
Joel Nylund on Aug 31
Hi Andre,
I dug deeper into my problem, and it appears this issue messes up my whole app, if I kill the app server and star again without geokit everything works again, but if not nothing seems to work:
Fri Aug 31 09:37:31 EDT 2007: Error calling Dispatcher.dispatch #
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:422:in `remove_const'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:422:in `remove_constant'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:273:in `remove_unloadable_constants!'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:273:in `remove_unloadable_constants!'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:72:in `clear'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:60:in `reset_application!'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:116:in `reset_after_dispatch'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/dispatcher.rb:51:in `dispatch'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/rails.rb:84:in `process'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/1.8/sync.rb:229:in `synchronize'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/rails.rb:83:in `process'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:580:in `process_client'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:579:in `process_client'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:686:in `run'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:686:in `run'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel.rb:673:in `run'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/configurator.rb:267:in `run'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/configurator.rb:266:in `run'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/bin/mongrel_rails:127:in `run'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/lib/mongrel/command.rb:211:in `run'
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/lib/ruby/gems/1.8/gems/mongrel-0.3.13.4/bin/mongrel_rails:231
/Applications/Locomotive2/Bundles/standardRailsSept2006.locobundle/i386/bin/mongrel_rails:18
any ideas?
Andre on Sep 07
@Kevin: AR loses the "distance" column when you use :include. If you have a resultset of acts_as_mappable models, you can call @addresses.sort_by_distance_from(origin) to get the distance values back. If the relationships of the models prevent you from using that, you may have to creatively post-process the result. One option is to iterate through the address results, calculate the distance from the origin, and add that distance attribute on to the *business* associated with that address. See the sort_by_distance_from implementation (at the bottom of acts_as_mappable.rb) for ideas on adding the distance column on-the-fly.
Let me know if you come up with a good, generalizable solution.
@Joel: I'm not sure what to say about this one. Is it possible it's a Locomotive thing? Is there any way you can try it on a non-Locomotive installation?
Michael Kedzierski on Sep 25
I spent some time stuck on the same bug that Joel is experiencing - I am not using locomotive and tried everything from Ubuntu-packaged rails, to gems, to edge.
What solved it in the end is taking out the "include GeoKit::Geocoders" from the top of my acts_as_mappable model file, and using the full reference to the MultiGeocoder in my code.
Nicolas Marchildon on Sep 25
Hello Andre,
I have a need to compute the distance of two lines, not just two points. In other words, my model objects have more than one point: origin_lat, origin_lng, destination_lat, destination_lng.
I tried calling acts_as_mappable twice with different column names, but I realized the method has a check against that. I would like to be able to sort by :order => 'origin_distance + destination_distance'.
Is this something you have been thinking about? Any workaround you know of?
What do you think of changing acts_as_mappable to be allowed to be called twice, with a new :prefix option also used by find, count, and others.
maner on Sep 26
Great work
I want only to submit a little bug, that I avoided by using :flat formula
>> include GeoKit::Mappable
=> Object
>> class TP (minor symbol) Struct.new(:lat,:lng)
>> end
=> nil
>>
?> p=TP.new(45.779291, 10.262985)
=> #
>>
?> p.distance_to(p)
Errno::EDOM: Domain error - acos
from ./script/../config/../config/../vendor/plugins/geokit/lib/geo_kit/m
appable.rb:37:in `acos'
from ./script/../config/../config/../vendor/plugins/geokit/lib/geo_kit/m
appable.rb:37:in `distance_between'
from ./script/../config/../config/../vendor/plugins/geokit/lib/geo_kit/m
appable.rb:74:in `distance_to'
from (irb):7
Regards
Massimo
maner on Sep 26
Sorry, ignore my last comment.
Bug is already mentioned in rubyforge projest as
bug ID 13243 (Numerical argument out of domain - acos)
Regards
Massimo
Roger Pack on Oct 19
If anyone experiences probs with distance_from([lat, longitude floats]) I submitted a patch for it. Also a patch for if you do a query with a string of (others) conditions it should work now with patch.
bolo on Oct 25
i try to upload the new version but i have this message
svn: Connection closed unexpectedly
Rob on Oct 30
The repository seems to be misbehaving. On my mac:
svn: Connection closed unexpectedly
Patrick on Nov 11
Geokit is simply amazing, nice work! I needed a geocoding solution, and I was prepared to create my own with TIGER/Line data and the geocoder.us python scripts... until I found Geokit! Saved me a huge-ass headache, for sure.
One small suggestion: You should make it clear, up front, that this plugin is released under the MIT license. I tried finding a license statement on this blog and on the rubyforge page, but no luck. Maybe I was totally oblivious and breezed right past it, but I didn't see it. I eventually found it by digging through my vendor directory.
I only assume that a plugin this powerful will eventually be rolled into some kind of public service, possibly even commercial. So, needless to say, the license info should be easy to find. Maybe put a little note next to the checkout instructions? Thanks!
With that aside, GREAT JOB!!!!
caius on Nov 14
Hi Kevin and Andre
I've seen a couple of people that have had problems such as kevin describes, i.e.
i have a model (e.g. listing) that 'belongs_to' a 'location', the location 'has_many' listings. I wanted to be able to things like
@listing = Listing.find_closest(:origin => home)
but my 'location' model is the thing that is geocodable. So I what I did was this:
in listings mode I do:
class Listing
acts_as_mappable
before_validation_on_create :geocode_address
before_validation_on_update :geocode_address
private
def geocode_address
self.lat = nil
self.lng = nil
errors.add("Address is invalid") if self.location.nil?
self.lat, self.lng = self.location.lat,self.location.lng
end
end
and in the location model:
class Location acts_as_mappable
has_many :listings
before_validation_on_create :geocode_address
before_validation_on_update :geocode_address
after_validation_on_update :copy_to_listings
private
def geocode_address
self.lat = nil
self.lng = nil
geo=GeoKit::Geocoders::MultiGeocoder.geocode (self.to_sentence)
errors.add(:address, "Could not Geocode address") if !geo.success
self.lat, self.lng = geo.lat,geo.lng if geo.success
end
def copy_to_listings
self.listings.each do |listing|
logger.info "XXXXX updaing listing #{listing.title}"
listing.lat, listing.lng = self.lat, self.lng
listing.save(false)
end
end
i.e. whenever the location is updated it copies over a lat, lng to the listing model, and when a listing is created or updated it pulls the lat lng from location. Ugly to have the same info stored in two places, but it seems to work okay.
btw: I love geokit, very nice. if only I could do joins with some full text searching (e.g. solr), I would be very happy.
Cheers
Ingo D on Dec 03
Any hints on how to install this through NetBeans on Windows? I do have subversion installed.
Paul M on Dec 07
I have been getting some strange results with MultiGeocoder.geocode( location ).
It appears that lat and lng are being flipped around?
Dale Cook on Dec 11
Andre,
I have a case where we need to include results that may actually not have geocode information, for example stores that exist online only, which would need to be included in our results even if they are not local.
I've modified the distance calculations to include results that have a null latitude by basically adding
OR (#{qualified_lat_column_name} IS NULL)
to the SQL in sphere_distance_sql and flat_distance_sql.
However, while this solves the problem it doesn't seem like a satisfactory solution to me (difficult to maintain going forward, prone to breaking on updates). Can you suggest a possible alternative?
Thanks
Dale
Tyler on Dec 13
Hey Andre,
I posted a while back about getting this up and running on Windows and its been working great!
This is the first time I've run into this issue (maybe its already been addressed?) but I have no idea how to troubleshoot this for my client's geocoding system.
I get the following:
Errno::EDOM
Domain error - acos
#{RAILS_ROOT}/vendor/plugins/geokit/lib/geo_kit/mappable.rb:41:in `acos'
I only get this error (I can recreate in the console too) when I try to get the distance between the exact same lat and lng (I'm geocoding using zip codes and they are the same zip (50309) ). It doesn't happen on any other zip codes or lat and lngs, just that one...any pointers/patches/fixes I should have to take care of this?
Tyler
David on Dec 27
Unable to install from rubyforge trying either [download] at rubyforge or ruby script/plugin install svn://rubyforge.org/var/svn/geokit
former yields error: "No File Packages
There are no file packages defined for this project."
and latter gives absolutely no error, no trace output.
did the projectfiles get lost from svn??
the [download] link is: http://rubyforge.org/frs/?group_id=3031&release_id=9912
Andre Lewis on Dec 27
@dave: rubyforge has been fickle lately, I've got a few emails from people who have had problems. But, I tried it just now (script/plugin install svn://rubyforge.org/var/svn/geokit) and (svn checkout svn://rubyforge.org/var/svn/geokit) and it worked.
I also posted a new .zip release of the code.
Cheers,
Andre
Billy on Jan 04
I have a question. This is the first time using GeoKit. I used the distance_to function to find the distance between 2 places. But why the result is different from the actual distance displayed on google or yahoo?
place.distance_to(@other_place, :units=>:miles)
-> result is 0.51 miles
-> result from google & yahoo is 0.94 miles
thanks
Will Jessop on Jan 16
Firstly, thanks for a really great plugin, Geokit has to be my favorite rails plugin of all time :)
I am also getting the error Tyler was getting:
I solved this by adding the line:
to the distance_between method:
def distance_between(from, to, options={}) from=GeoKit::LatLng.normalize(from) to=GeoKit::LatLng.normalize(to) return 0.0 if from == to units = options[:units] || GeoKit::default_units formula = options[:formula] || GeoKit::default_formula ...Could this be added to a release?
Thanks
Andre Lewis on Jan 20
@Billy - Google and Yahoo are calculating the driving distance along roads. GeoKit is calculating the straight-line "as the crow flies" distance.
@Will - you got it! I added it to GeoKit
Andre
Nate Bird on Feb 14
Any ideas on extending this to also pull the county information if available? In the meantime I'll try to hack it myself. If I come up with a usable solution I'll post a patch.
TobStarr on Mar 05
Hi,
first of all thanx for creating and maintaining GeoKit. It did help me and still helps me a lot in my everyday work. I have a question regarding queries like this:
Place.find(:all, :origin => a_place, :conditions => "distance
Why is GeoKit not automatically adding the corresponding bounding box to the where statement of the SQL query? The default is to calculate the distance from the origin to every single point in the places table and do the filtering after that. With bounds one could use an index (e.g. a combined one on the lat and lng columns), filter the places in that bounding box and only calculate the distance to those. I know I can add the bounds myself (with :bounds => ...), question is why don't you do it automatically?
Thanx,
Tobi
David on Mar 09
Does GeoKit use the spatial features of MySQL/PostgreSQL or just basic trig?
Presumably, the bounding box optimization works best when lat and lng are indexed. Is it best to use a combined one on the lat and lng columns (as TobStarr suggested) or doesn't it matter?
Andre Lewis on Mar 09
@Tobi: when I originally created the bounds logic, I ran some tests to see if MySQL was smart enough to use the bounding box as a limiting clause before it went through the trig situps for the distance query. Unfortunately, as far as I could tell, it wasn't smart enough. Therefore, no default bounding box restriction on the spherical queries. Now, I didn't spend a ton of time on it, so I may have set something up wrong or misread the results -- if anyone can establish otherwise, let me know.
@David: GeoKit uses trig. At the time GeoKit was implemented, the MySQL spatial features didn't actually work as documented.
And yes, if you're doing bounding box queries, you should have a combined index on lat and lng columns.
CANT GET PLUGIN on Mar 13
GEE, I'D REALLY LOVE TO USE THIS PLUGIN. CAN'T FREAKIN GET IT OUT OF YOUR REPOSITORY. TRIED TO INSTALL SVN FOLLOWING THOSE COMMENTS ABOVE, STILL NO HELP. WHY DO YOU MAKE IT SO HARD TO GET THE PLUGIN? I GET MANY OTHER RAILS PLUGINS VERY EASILY. I NEVER HAD THIS MUCH TROUBLE BEFORE. MAYBE YOU OUGHTA MAKE THE PLUGIN INSTALL USER FRIENDLY?
Adiyanta Kosasi on Mar 17
Hello,
I'm a newcomer using ROR which is still learning until now. Recently i try to build an application to show the distance between 2 location. When i check the result using google, i found it's different from mine's result.
You mention "Google and Yahoo are calculating the driving distance along roads. GeoKit is calculating the straight-line "as the crow flies" distance." above...
I was wondering whether someday GeoKit will be able to count the distance along roads too, just like google and yahoo...
Thank you,
Adi
Yudi Soesanto on Mar 17
Andre,
How I can calculate a distance between 2 points? I use distance_to to calculate 2 points . The distance showed not the same with google map? Could you give me code example to calculate the distance of 2 points?
Andre Lewis on Mar 17
@Can't get plugin -- it's a standard rubyforge repo.
@Adiyanta, Yudi -- calculating distance along roads is a much more involved than calculating straight-line distances. If a free API because available for this, I'll look at integrating it (or look for patches to do so).
Google Maps does have a routing / driving directions API, but it is JavaScript only: http://code.google.com/apis/maps/documentation/services.html#Driving_Directions
Adiyanta Kosasi on Mar 19
Thanks a lot for the information. I do really appreciate it...
Andrea on Apr 04
Hi to all,
i've changed my file mappable.rb to fix the "acos" and "zero-distance" bug, but i've still a compile error while i'm using that function....
I've to do something more than only modify the file???
Thanks
Andre Lewis on Apr 04
@Andrea -- if you get the latest GeoKit code, you shouldn't need to change anything. I fixed the zero-distance bug a while ago.
stacey on Apr 10
thanks for the plugin! i was wondering if you can map just the state or the country instead of a street address. i get a nil value when my address is only a state name. is there a way to return the center coords for the state? thanks.
Andre Lewis on Apr 10
@stacey: states should work:
>>r=GeoKit::Geocoders::GoogleGeocoder.geocode('california') >> r.full_address => "California, USA" >> r=GeoKit::Geocoders::GoogleGeocoder.geocode('nevada') >> r.full_address => "Nevada, USA" >> [r.lat,r.lng] => [38.502147, -117.022694] >>Adiyanta Kosasi on Apr 16
Hello,
About last month, i put a post in this blog, asking about why the distance calculated between 2 places using geokit and the feature at maps.google.com are not equal.
I've visit the link you mentioned and try to use it. But i'm still wondering whether there are any ruby plugin that can calculate the distance equally to google maps feature.
If you don't mind, may i know whether you have any plan to develop this kind of plugin or not.
Thank you,
Adi
Rochak Chauhan on May 01
Well,
If you are looking for a simple HTTP based API, then take a look at GeoIP API at: http://geoip.dmwtechnologies.com.
It is the all in one API, which can extract Country, Capital, State/Region, City, Area code, Metro code,PIN code, Currency, Calling Code, Current Conversion rate(with USD), Local Time, Current Weather, Latitude, Longitude and more information just from the IP address. All this for FREE
People call it WOW...but we call it IP Intelligence :)