# Geo Code

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 ?

thanks

Cyrus D. 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)

R=3958

def get_distance_to(to_lat, to_lon)

`````` 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

Thanks Andrew

but is there a way that i can do with geo code kit ?

any idea ?

Andrew P. wrote:

Cyrus D. 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)

R=3958

def get_distance_to(to_lat, to_lon)

`````` 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

On Thu, Feb 19, 2009 at 12:57 AM, Cyrus D. <
[email protected]> wrote:

`````` lon1=self.longitude * RadConv

return d;
``````

end