I am struggling to format the way that geocoder is returning the distance from one location to another.
Here is the code:
Jbuilder file:
json.array! results do |result|
json.distance result.distance_from(@geocoded_location, units: :miles)
end
Methods:
def geocoded_location
return unless postcode
@geocoded_location ||= geocoder.geocode(postcode, bias: 'uk')
end
def geocoder
Geokit::Geocoders::GoogleGeocoder
end
def postcode
@postcode ||= params[:searchterm]
end
Now I think this all works but the result I get back is 3562.6325498137753 for the first location in the results array.
Is there a way to format the response as that is definitely not returning in miles as the two locations are less than 2 miles apart. Thought it might have been feet or meters but they are all roughly the same distance wherever you put the search from. So I think it is an issue with the geocoded location.
We are using gem 'geokit'
Any ideas or help would be greatly appreciated. If you need any further code let me know.