Forum: Ruby on Rails Geo Code

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7694e527192e45b73b95f2ca41034463?d=identicon&s=25 Cyrus Dev (cyrusdev)
on 2009-02-19 08:02
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
613340c5fef56ad6fc3bf8cc617266ae?d=identicon&s=25 Andrew Porter (Guest)
on 2009-02-19 09:55
(Received via mailing list)
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
7694e527192e45b73b95f2ca41034463?d=identicon&s=25 Cyrus Dev (cyrusdev)
on 2009-02-19 09:57
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
40db9e75b3f5899258e3bdc0c9210154?d=identicon&s=25 Conrad Taylor (Guest)
on 2009-02-19 10:02
(Received via mailing list)
On Thu, Feb 19, 2009 at 12:57 AM, Cyrus Dev <
rails-mailing-list@andreas-s.net> wrote:

> >>
> >      lon1=self.longitude * RadConv
> >
> >      return d;
> >    end
>

Hi, please read the following:

http://geokit.rubyforge.org/

Good luck,

-Conrad
This topic is locked and can not be replied to.