I'm using the Geocoder gem to calculate the distance between some locations and the users location. I'm also manually plugging in the coordinates to measure the distance and the values are totally off.
Inside the serialized model:
attribute :distance_to_user do
if @user_location.present?
locale = @language.locale
units = (I18n.t "distance.thousand.other", default: "km").to_sym
distance = @object.distance_to(@user_location, units)
converted_distance = LocationsHelper.convert_distance(locale, distance)
ActionController::Base.helpers.number_to_human(converted_distance, units: :distance, format: "%n%u")
end
end
LocationHelper
def convert_distance(locale, distance)
return distance if locale.eql?("en-US")
distance * 1000
end
@user_location
returns the correct coordinate for the user and @object
has the correct coordinates for the items location but the distance calculated is totally off.