Class: Motion::Distance
- Inherits:
-
Object
- Object
- Motion::Distance
- Defined in:
- lib/motion/distance.rb
Instance Attribute Summary collapse
-
#accuracy ⇒ Object
Returns the value of attribute accuracy.
-
#activity_type ⇒ Object
Returns the value of attribute activity_type.
-
#distance_filter ⇒ Object
Returns the value of attribute distance_filter.
Instance Method Summary collapse
- #get(&block) ⇒ Object
-
#initialize(args = {}) ⇒ Distance
constructor
A new instance of Distance.
- #location_manager ⇒ Object
- #locationManager(locationManager, didFailWithError: error) ⇒ Object
- #stop_updating ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Distance
Returns a new instance of Distance.
5 6 7 8 9 10 |
# 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 |
Instance Attribute Details
#accuracy ⇒ Object
Returns the value of attribute accuracy.
3 4 5 |
# File 'lib/motion/distance.rb', line 3 def accuracy @accuracy end |
#activity_type ⇒ Object
Returns the value of attribute activity_type.
3 4 5 |
# File 'lib/motion/distance.rb', line 3 def activity_type @activity_type end |
#distance_filter ⇒ Object
Returns the value of attribute distance_filter.
3 4 5 |
# File 'lib/motion/distance.rb', line 3 def distance_filter @distance_filter end |
Instance Method Details
#get(&block) ⇒ Object
12 13 14 15 16 |
# File 'lib/motion/distance.rb', line 12 def get(&block) @callback = block @total = 0 location_manager.startUpdatingLocation end |
#location_manager ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 |
# 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 |
#locationManager(locationManager, didFailWithError: error) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# 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 |
#stop_updating ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/motion/distance.rb', line 18 def stop_updating location_manager.stopUpdatingLocation @total = 0 @last_location = nil @callback = nil end |