Module: BubbleWrap::Location
- Defined in:
- motion/location/location.rb
Defined Under Namespace
Modules: Error
Class Method Summary collapse
-
.authorized? ⇒ Boolean
returns true/false whether services are enabled for the app.
-
.enabled? ⇒ Boolean
returns true/false whether services, or limited services, are enabled for the device.
- .error(type) ⇒ Object
- .get(options = {}, &block) ⇒ Object
- .get_compass(options = {}, &block) ⇒ Object
- .get_compass_once(options = {}, &block) ⇒ Object
-
.get_once(options = {}, &block) ⇒ Object
Get the first returned location based on your options } Example BW::Location.get_once(desired_accuracy: :three_kilometers, purpose: ‘We need to use your GPS to show you how fun RM is’) do |result| if result.is_a?(CLLocation) p “Lat #resultresult.latitude, Long #resultresult.longitude” else p “ERROR: #{result” end end.
- .get_significant(options = {}, &block) ⇒ Object
-
.initialized? ⇒ Boolean
returns true/false if CLLocationManager has been initialized with the provided or default options.
- .location_manager ⇒ Object
-
.locationManager(manager, didChangeAuthorizationStatus: status) ⇒ Object
CLLocationManagerDelegate Methods.
- .locationManagerShouldDisplayHeadingCalibration(manager) ⇒ Object
-
.start ⇒ Object
Start getting locations.
-
.stop ⇒ Object
Stop getting locations.
Class Method Details
.authorized? ⇒ Boolean
returns true/false whether services are enabled for the app
175 176 177 178 179 |
# File 'motion/location/location.rb', line 175 def [ BW::Constants.get("KCLAuthorizationStatus", :authorized) ].include?(CLLocationManager.) end |
.enabled? ⇒ Boolean
returns true/false whether services, or limited services, are enabled for the device
165 166 167 |
# File 'motion/location/location.rb', line 165 def enabled? CLLocationManager.locationServicesEnabled end |
.error(type) ⇒ Object
181 182 183 184 185 |
# File 'motion/location/location.rb', line 181 def error(type) @callback && @callback.call({ error: type }) @callback = nil self.location_manager.stopUpdatingLocation end |
.get(options = {}, &block) ⇒ Object
Start getting locations } Example BW::Location.get(distance_filter: 10, desired_accuracy: :nearest_ten_meters) do |result|
result[:to].class == CLLocation
result[:from].class == CLLocation
result[:previous].class == NSArray<CLLocation>
p "Lat #{result[:to].latitude}, Long #{result[:to].longitude}"
end
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'motion/location/location.rb', line 57 def get( = {}, &block) @callback = block @callback.weak! if @callback && BubbleWrap.use_weak_callbacks? = { authorization_type: :always, significant: false, distance_filter: KCLDistanceFilterNone, desired_accuracy: KCLLocationAccuracyBest, retries: 5, once: false, calibration: false }.merge() [:significant] = false if [:significant].nil? @retries = 0 @from_location = nil if not enabled? error(Error::DISABLED) and return end self.location_manager if self.location_manager.respondsToSelector('requestAlwaysAuthorization') [:authorization_type] == :always ? self.location_manager.requestAlwaysAuthorization : self.location_manager.requestWhenInUseAuthorization end self.location_manager.distanceFilter = [:distance_filter] self.location_manager.desiredAccuracy = Constants.get("KCLLocationAccuracy", [:desired_accuracy]) self.location_manager.purpose = [:purpose] if [:purpose] @initialized = true start end |
.get_compass(options = {}, &block) ⇒ Object
126 127 128 |
# File 'motion/location/location.rb', line 126 def get_compass( = {}, &block) get(.merge(compass: true), &block) end |
.get_compass_once(options = {}, &block) ⇒ Object
130 131 132 |
# File 'motion/location/location.rb', line 130 def get_compass_once( = {}, &block) get_compass(.merge(once: true), &block) end |
.get_once(options = {}, &block) ⇒ Object
Get the first returned location based on your options } Example BW::Location.get_once(desired_accuracy: :three_kilometers, purpose: ‘We need to use your GPS to show you how fun RM is’) do |result|
if result.is_a?(CLLocation)
p "Lat #{result.latitude}, Long #{result.longitude}"
else
p "ERROR: #{result[:error]"
end
end
122 123 124 |
# File 'motion/location/location.rb', line 122 def get_once( = {}, &block) get(.merge(once: true), &block) end |
.get_significant(options = {}, &block) ⇒ Object
93 94 95 |
# File 'motion/location/location.rb', line 93 def get_significant( = {}, &block) get(.merge(significant: true), &block) end |
.initialized? ⇒ Boolean
returns true/false if CLLocationManager has been initialized with the provided or default options
170 171 172 |
# File 'motion/location/location.rb', line 170 def initialized? @initialized ||= false end |
.location_manager ⇒ Object
158 159 160 161 162 |
# File 'motion/location/location.rb', line 158 def location_manager @location_manager ||= CLLocationManager.alloc.init @location_manager.delegate ||= self @location_manager end |
.locationManager(manager, didChangeAuthorizationStatus: status) ⇒ Object
CLLocationManagerDelegate Methods
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'motion/location/location.rb', line 189 def locationManager(manager, didUpdateLocations:locations) if [:once] @callback && @callback.call(locations.last) @callback = proc { |result| } stop else size = locations.count result = {to: locations.last, from: ( (size > 1) ? locations.last(2).first : @from_location ), previous: ( (size > 2) ? locations.first(size - 2) : [] ) } @from_location = result[:to] @callback && @callback.call(result) end end |
.locationManagerShouldDisplayHeadingCalibration(manager) ⇒ Object
252 253 254 |
# File 'motion/location/location.rb', line 252 def locationManagerShouldDisplayHeadingCalibration(manager) [:calibration] ? [:calibration] : false end |
.start ⇒ Object
Start getting locations
135 136 137 138 139 140 141 142 143 144 |
# File 'motion/location/location.rb', line 135 def start return unless initialized? if [:significant] self.location_manager.startMonitoringSignificantLocationChanges elsif [:compass] self.location_manager.startUpdatingHeading else self.location_manager.startUpdatingLocation end end |
.stop ⇒ Object
Stop getting locations
147 148 149 150 151 152 153 154 155 156 |
# File 'motion/location/location.rb', line 147 def stop return unless if [:significant] self.location_manager.stopMonitoringSignificantLocationChanges elsif [:compass] self.location_manager.stopUpdatingHeading else self.location_manager.stopUpdatingLocation end end |