From c4fc30d90433a98d3e853e61f19b56945325766a Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Wed, 15 Apr 2009 23:51:24 -0400 Subject: [PATCH] Add distance_to method. --- lib/geocoder.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/geocoder.rb b/lib/geocoder.rb index f8a5091e..df03e5a5 100644 --- a/lib/geocoder.rb +++ b/lib/geocoder.rb @@ -23,6 +23,14 @@ module Geocoder coords.split(',')[0...2].reverse.map{ |i| i.to_f } end + ## + # Calculate the distance from the object to a point (lat,lon). Valid units + # are defined in <tt>distance_between</tt> class method. + # + def distance_to(lat, lon, units = :mi) + Geocoder.distance_between(latitude, longitude, lat, lon, :units => units) + end + ## # Search Google based on the object's +location+ attribute. # -- GitLab