motion-locman 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/locman/location.rb +30 -5
- data/lib/locman/manager.rb +44 -1
- data/lib/locman/visit.rb +27 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d10b5eb84ea2563bcdf3855ac254eb7c1a85d0f2
|
4
|
+
data.tar.gz: a8a2d3c27c772c9821d05551b734db70184955ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 989c5daccea667c113e2b9905b7e551e32cfc278210930a28633ad83bb111281d112073b2679acacb758374579d9f5409136cd2d987e8d6f341646de247ca910
|
7
|
+
data.tar.gz: 9a67a845e19079d6a1770c25781e24904cceb74c3031fef5af60c6dbd6b2a722347f3e1e61e115f8dd4845d39f016f170788f0821bdb8a6e9fe336cdd4fd7574
|
data/lib/locman/location.rb
CHANGED
@@ -1,9 +1,30 @@
|
|
1
1
|
module Locman
|
2
|
+
# This represents a single location point.
|
2
3
|
class Location
|
3
|
-
|
4
|
-
|
5
|
-
:determined_at
|
4
|
+
# @return [Float] Latitude coordinate of the location.
|
5
|
+
attr_accessor :latitude
|
6
6
|
|
7
|
+
# @return [Float] Longitude coordinate of the location
|
8
|
+
attr_accessor :longitude
|
9
|
+
|
10
|
+
# @return [Float] Altitude distance measurement of the location, in meters.
|
11
|
+
attr_accessor :altitude
|
12
|
+
|
13
|
+
# @return [Integer] The logical floor of the building.
|
14
|
+
attr_accessor :floor
|
15
|
+
|
16
|
+
# @return [Float] Latitude and longitude measurement accuracy, in meters.
|
17
|
+
attr_accessor :accuracy
|
18
|
+
|
19
|
+
# @return [Float] Altitude measurement accuracy, in meters.
|
20
|
+
attr_accessor :altitude_accuracy
|
21
|
+
|
22
|
+
# @return [Time] The time at which this location was determined
|
23
|
+
attr_accessor :determined_at
|
24
|
+
|
25
|
+
# Creates a new Locman::Location instance from CLLocation object.
|
26
|
+
# @param cl_location [CLLocation]
|
27
|
+
# @return [Locman::Location]
|
7
28
|
def self.create_from_cl_location(cl_location)
|
8
29
|
Locman::Location.new(
|
9
30
|
latitude: cl_location.coordinate.latitude,
|
@@ -16,8 +37,12 @@ module Locman
|
|
16
37
|
)
|
17
38
|
end
|
18
39
|
|
19
|
-
|
20
|
-
|
40
|
+
# Creates a new Locman::Location instance.
|
41
|
+
# @param options [Hash] Attributes that will be assigned on instance creation
|
42
|
+
# @return [Locman::Location]
|
43
|
+
def initialize(options = {})
|
44
|
+
options.each { |key, value| send("#{key}=", value) }
|
45
|
+
self
|
21
46
|
end
|
22
47
|
end
|
23
48
|
end
|
data/lib/locman/manager.rb
CHANGED
@@ -1,19 +1,36 @@
|
|
1
1
|
module Locman
|
2
|
+
# This wraps CLLocationManager in more Ruby way.
|
2
3
|
class Manager
|
3
|
-
|
4
|
+
# @return [Symbol] Desired accuracy of the location data.
|
5
|
+
attr_accessor :accuracy
|
4
6
|
|
7
|
+
# @return [Integer] The minimum horizontal distance threshold for on_update event.
|
8
|
+
attr_accessor :distance_filter
|
9
|
+
|
10
|
+
# @return [Proc] Proc function that will be called when there is a new location retrieval.
|
11
|
+
attr_accessor :on_update
|
12
|
+
|
13
|
+
# @return [Proc] Proc function that will be called when there is an error while retrieving the location.
|
14
|
+
attr_accessor :on_error
|
15
|
+
|
16
|
+
# @return [Proc] Proc function that will be called when there is a new visit event.
|
17
|
+
attr_accessor :on_visit
|
18
|
+
|
19
|
+
# @!visibility private
|
5
20
|
AUTHORIZED_CONSTS = [
|
6
21
|
KCLAuthorizationStatusAuthorized,
|
7
22
|
KCLAuthorizationStatusAuthorizedAlways,
|
8
23
|
KCLAuthorizationStatusAuthorizedWhenInUse
|
9
24
|
]
|
10
25
|
|
26
|
+
# @!visibility private
|
11
27
|
NOT_AUTHORIZED_CONSTS = [
|
12
28
|
KCLAuthorizationStatusNotDetermined,
|
13
29
|
KCLAuthorizationStatusRestricted,
|
14
30
|
KCLAuthorizationStatusDenied
|
15
31
|
]
|
16
32
|
|
33
|
+
# @!visibility private
|
17
34
|
ACCURACY_MAP = {
|
18
35
|
navigation: KCLLocationAccuracyBestForNavigation,
|
19
36
|
best: KCLLocationAccuracyBest,
|
@@ -23,13 +40,20 @@ module Locman
|
|
23
40
|
three_kilometers: KCLLocationAccuracyThreeKilometers
|
24
41
|
}
|
25
42
|
|
43
|
+
# Creates a new Locman::Location instance.
|
44
|
+
# @param options [Hash] Attributes that will be assigned on instance creation
|
45
|
+
# @return [Locman::Manager]
|
26
46
|
def initialize(params = {})
|
27
47
|
params.each { |key, value| send("#{key}=", value) }
|
28
48
|
|
29
49
|
@accuracy ||= :best
|
30
50
|
@distance_filter ||= 0
|
51
|
+
|
52
|
+
self
|
31
53
|
end
|
32
54
|
|
55
|
+
# Sets a desired accuracy.
|
56
|
+
# @param accuracy [Symbol] Desired accuracy of the location data.
|
33
57
|
def accuracy=(accuracy)
|
34
58
|
fail(ArgumentError, "Invalid accuracy: #{accuracy}") if ACCURACY_MAP[accuracy].nil?
|
35
59
|
@accuracy = accuracy
|
@@ -78,6 +102,14 @@ module Locman
|
|
78
102
|
manager.startMonitoringSignificantLocationChanges
|
79
103
|
end
|
80
104
|
|
105
|
+
def start_monitor_visits!
|
106
|
+
manager.startMonitoringVisits
|
107
|
+
end
|
108
|
+
|
109
|
+
def stop_monitor_visits!
|
110
|
+
manager.stopMonitoringVisits
|
111
|
+
end
|
112
|
+
|
81
113
|
def stop_monitor!
|
82
114
|
manager.stopMonitoringSignificantLocationChanges
|
83
115
|
end
|
@@ -92,6 +124,11 @@ module Locman
|
|
92
124
|
@on_error = on_error
|
93
125
|
end
|
94
126
|
|
127
|
+
def on_visit=(on_visit)
|
128
|
+
fail(ArgumentError, "Must provide proc") unless on_error.is_a?(Proc)
|
129
|
+
@on_visit = on_visit
|
130
|
+
end
|
131
|
+
|
95
132
|
# Delegates
|
96
133
|
|
97
134
|
def locationManager(manager, didChangeAuthorizationStatus: status)
|
@@ -110,6 +147,12 @@ module Locman
|
|
110
147
|
@on_update.call(locations) unless @on_update.nil?
|
111
148
|
end
|
112
149
|
|
150
|
+
def locationManager(manager, didVisit: cl_visit)
|
151
|
+
visit = Locman::Visit.create_from_cl_visit(cl_visit)
|
152
|
+
|
153
|
+
@on_visit.call(visit) unless @on_visit.nil?
|
154
|
+
end
|
155
|
+
|
113
156
|
private
|
114
157
|
|
115
158
|
def manager
|
data/lib/locman/visit.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Locman
|
2
|
+
# This represents a single visit.
|
3
|
+
class Visit
|
4
|
+
attr_accessor :latitude, :longitude, :departed_at, :arrived_at
|
5
|
+
|
6
|
+
# Creates a new Locman::Location instance from CLVisit object.
|
7
|
+
# @param cl_visit [CLVisit]
|
8
|
+
# @return [Locman::Location]
|
9
|
+
def self.create_from_cl_visit(cl_visit)
|
10
|
+
Locman::Visit.new(
|
11
|
+
latitude: cl_visit.coordinate.latitude,
|
12
|
+
longitude: cl_visit.coordinate.longitude,
|
13
|
+
departed_at: cl_visit.departureDate,
|
14
|
+
arrived_at: cl_visit.arrivalDate
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Creates a new Locman::Location instance.
|
19
|
+
# @param options [Hash] Attributes that will be assigned on instance creation
|
20
|
+
# @return [Locman::Location]
|
21
|
+
def initialize(options = {})
|
22
|
+
options.each { |key, value| send("#{key}=", value) }
|
23
|
+
self
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: motion-locman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Minku Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -35,6 +35,7 @@ files:
|
|
35
35
|
- lib/locman.rb
|
36
36
|
- lib/locman/location.rb
|
37
37
|
- lib/locman/manager.rb
|
38
|
+
- lib/locman/visit.rb
|
38
39
|
- lib/motion-locman.rb
|
39
40
|
homepage: https://github.com/premist/motion-locman
|
40
41
|
licenses:
|
@@ -61,3 +62,4 @@ signing_key:
|
|
61
62
|
specification_version: 4
|
62
63
|
summary: Simple location library for Rubymotion. Wraps CLLocationManager and more.
|
63
64
|
test_files: []
|
65
|
+
has_rdoc:
|