Geocoder is not precise using #km_in_mi constant

72 Views Asked by At

I am building a system using ruby on rails and we rely on geocoder to work with latitude and longitude and addresses.

I am using geocoder to calculate the distance between two points like this:

Geocoder::Calculations.distance_between([lat1, lon1], [lat2, lon2])

But the result comes in miles. So i had to convert from miles to Km. The geocoder docs says that:

Geocoder::Calculations.to_kilometers

Is deprecated and I need to multiply by this constant:

Geocoder::Calculations.km_in_mi

And that is the problem when I do this:

Geocoder::Calculations.distance_between([lat1, lon1], [lat2, lon2]) * Geocoder::Calculations.km_in_mi

The result is really imprecise, instead I use the deprecated way and the result works perfectly like this:

Geocoder::Calculations.to_kilometers(Geocoder::Calculations.distance_between([lat1, lon1], [lat2, lon2]))

So, I was wondering why is this happening? Am I missing something or making a silly mistake? Is it a problem to use Geocoder::Calculations.to_kilometers?

Thanks in advance

0

There are 0 best solutions below