Hello Everyone, any one has idea abt geocode ? in rails I want to find distance in miles between 2 points , I have lattitude and longitude of both points , how can i do that ? please help me thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Cyrus Dev wrote:> > I want to find distance in miles between 2 points , I have lattitude and > longitude of both points ,I do this (inside a model what has latitude and longitude attributes) RadConv=(Math::PI/180) R=3958 def get_distance_to(to_lat, to_lon) lat1=self.latitude * RadConv lon1=self.longitude * RadConv lat2=to_lat * RadConv lon2=to_lon * RadConv diff_lon = (lon2 - lon1).abs diff_lat = (lat2 - lat1).abs a = Math.sin(diff_lat/2) * Math.sin(diff_lat/2) + Math.cos(lat1) * Math.cos(lat2) * Math.sin(diff_lon/2) * Math.sin(diff_lon/2); c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); d = R * c; return d; end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks Andrew but is there a way that i can do with geo code kit ? any idea ? Andrew Porter wrote:> Cyrus Dev wrote: >> >> I want to find distance in miles between 2 points , I have lattitude and >> longitude of both points , > > I do this (inside a model what has latitude and longitude attributes) > > RadConv=(Math::PI/180) > R=3958 > > def get_distance_to(to_lat, to_lon) > lat1=self.latitude * RadConv > lon1=self.longitude * RadConv > lat2=to_lat * RadConv > lon2=to_lon * RadConv > > diff_lon = (lon2 - lon1).abs > diff_lat = (lat2 - lat1).abs > > a = Math.sin(diff_lat/2) * Math.sin(diff_lat/2) + Math.cos(lat1) * > Math.cos(lat2) * Math.sin(diff_lon/2) * Math.sin(diff_lon/2); > c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); > d = R * c; > > return d; > end-- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Thu, Feb 19, 2009 at 12:57 AM, Cyrus Dev < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Thanks Andrew > > but is there a way that i can do with geo code kit ? > > any idea ? > > Andrew Porter wrote: > > Cyrus Dev wrote: > >> > >> I want to find distance in miles between 2 points , I have lattitude and > >> longitude of both points , > > > > I do this (inside a model what has latitude and longitude attributes) > > > > RadConv=(Math::PI/180) > > R=3958 > > > > def get_distance_to(to_lat, to_lon) > > lat1=self.latitude * RadConv > > lon1=self.longitude * RadConv > > lat2=to_lat * RadConv > > lon2=to_lon * RadConv > > > > diff_lon = (lon2 - lon1).abs > > diff_lat = (lat2 - lat1).abs > > > > a = Math.sin(diff_lat/2) * Math.sin(diff_lat/2) + Math.cos(lat1) * > > Math.cos(lat2) * Math.sin(diff_lon/2) * Math.sin(diff_lon/2); > > c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); > > d = R * c; > > > > return d; > > end >Hi, please read the following: http://geokit.rubyforge.org/ Good luck, -Conrad --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---