class Motion::Distance
Attributes
accuracy[RW]
activity_type[RW]
distance_filter[RW]
Public Class Methods
new(args = {})
click to toggle source
# File lib/motion/distance.rb, line 5 def initialize(args = {}) self.accuracy = args[:accuracy] || KCLLocationAccuracyBest self.activity_type = args[:activity_type] || CLActivityTypeOther self.distance_filter = args[:distance_filter] || KCLDistanceFilterNone self end
Public Instance Methods
get(&block)
click to toggle source
# File lib/motion/distance.rb, line 12 def get(&block) @callback = block @total = 0 location_manager.startUpdatingLocation end
locationManager(locationManager, didUpdateLocations: locations)
click to toggle source
# File lib/motion/distance.rb, line 26 def locationManager(locationManager, didUpdateLocations: locations) locations.each do |location| if location.horizontalAccuracy <= 5.0 @total += location.distanceFromLocation(@last_location) @last_location = location response = { total: @total, location: location } @callback.call response end end end
location_manager()
click to toggle source
# File lib/motion/distance.rb, line 45 def location_manager @location_manager ||= begin manager = CLLocationManager.alloc.init manager.desiredAccuracy = self.accuracy manager.activityType = self.activity_type manager.distanceFilter = self.distance_filter manager.delegate = self manager end end
stop_updating()
click to toggle source
# File lib/motion/distance.rb, line 18 def stop_updating location_manager.stopUpdatingLocation @total = 0 @last_location = nil @callback = nil end