class Geolocutor
Wrap Geocoder gem to calculate relative distances
Attributes
coordinates[R]
Public Class Methods
new(location, metric = false)
click to toggle source
# File lib/geolocutor.rb, line 10 def initialize(location, metric = false) @coordinates = coordinatize(location) @metric = metric end
Public Instance Methods
distance_from_here(there)
click to toggle source
# File lib/geolocutor.rb, line 15 def distance_from_here(there) there = coordinatize(extract_coordinates(there)) distance = Geocoder::Calculations.distance_between(@coordinates, there) return Geocoder::Calculations.to_kilometers(distance) if @metric Geocoder::Calculations.to_miles(distance) end
Private Instance Methods
coordinatize(location)
click to toggle source
# File lib/geolocutor.rb, line 25 def coordinatize(location) fail(ArgumentError, 'You must supply coordinates, and address or a location name') if location.nil? Geocoder.coordinates(location) end
extract_coordinates(vehicle_json)
click to toggle source
car2go reverses the lat/long and also includes an accuracy value which must be removed
# File lib/geolocutor.rb, line 32 def extract_coordinates(vehicle_json) coordinates = vehicle_json['coordinates'] coordinates.pop coordinates.reverse end