motion-distance 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 +7 -0
- data/README.md +65 -0
- data/lib/motion-distance.rb +9 -0
- data/lib/motion/distance.rb +49 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 419bcf40f8964936b49b0ab8b6720cd9d46be693
|
4
|
+
data.tar.gz: a022d6885be32f527083a140954af237469fa689
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b2b41702229ae08411b5a587284c0a18298f1de06388092b55b4c517aed79ccb4ce787ffb3a71d648417069e62ca82e50b20fa27febbac0c80e7a0e91a4b36bc
|
7
|
+
data.tar.gz: 00bdd42ca66e9f1bc7b7ca7fb4c6154ac6afa41cf413cd71b57ad37e1f791cbb680915d3e1574d4d5ac63e40367a6273abe1bed99677e7adf7c4fd11246c6892
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# motion-distance
|
2
|
+
|
3
|
+
Easy distance tracking for RubyMotion projects.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem "motion-distance"
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Create a new instance of `Motion::Distance`.
|
18
|
+
|
19
|
+
You must also specify an activity type. This will help the OS know when to pause and resume updates that will help save battery.
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
# CLActivityTypeOther,
|
23
|
+
# CLActivityTypeAutomotiveNavigation,
|
24
|
+
# CLActivityTypeFitness,
|
25
|
+
# CLActivityTypeOtherNavigation,
|
26
|
+
|
27
|
+
@distance = Motion::Distance.new
|
28
|
+
@distance.activity_type = CLActivityTypeFitness
|
29
|
+
```
|
30
|
+
|
31
|
+
You may also set a level of accuracy.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
KCLLocationAccuracyBestForNavigation
|
35
|
+
KCLLocationAccuracyBest
|
36
|
+
KCLLocationAccuracyNearestTenMeters
|
37
|
+
KCLLocationAccuracyHundredMeters
|
38
|
+
KCLLocationAccuracyKilometer
|
39
|
+
KCLLocationAccuracyThreeKilometers
|
40
|
+
```
|
41
|
+
|
42
|
+
Now you can call `#get` to begin tracking any distance travelled. Each time the phone registers a location change
|
43
|
+
you'll recieve a hash that contains the total distance travelled and current location.
|
44
|
+
|
45
|
+
Distance is always returned in meters.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
@distance.get do |location|
|
49
|
+
puts location[:total]
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
You can stop tracking location by calling:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
@distance.stop_updating
|
57
|
+
```
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
1. Fork it
|
62
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
63
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
64
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
65
|
+
5. Create new Pull Request
|
@@ -0,0 +1,9 @@
|
|
1
|
+
unless defined?(Motion::Project::Config)
|
2
|
+
raise "This file must be required within a RubyMotion project Rakefile."
|
3
|
+
end
|
4
|
+
|
5
|
+
lib_dir_path = File.dirname(File.expand_path(__FILE__))
|
6
|
+
Motion::Project::App.setup do |app|
|
7
|
+
app.files.unshift(Dir.glob(File.join(lib_dir_path, "motion/**/*.rb")))
|
8
|
+
app.frameworks += ["CoreLocation"]
|
9
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Motion
|
2
|
+
class Distance
|
3
|
+
attr_accessor :activity_type, :accuracy
|
4
|
+
|
5
|
+
def get(&block)
|
6
|
+
@callback = block
|
7
|
+
@total = 0
|
8
|
+
location_manager.startUpdatingLocation
|
9
|
+
end
|
10
|
+
|
11
|
+
def stop_updating
|
12
|
+
location_manager.stopUpdatingLocation
|
13
|
+
|
14
|
+
@total_distance = 0
|
15
|
+
@last_location = nil
|
16
|
+
@callback = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def locationManager(locationManager, didUpdateLocations: locations)
|
20
|
+
locations.each do |location|
|
21
|
+
if location.horizontalAccuracy <= 5.0
|
22
|
+
@total += location.distanceFromLocation(@last_location)
|
23
|
+
@last_location = location
|
24
|
+
response = { total: @total, location: location }
|
25
|
+
|
26
|
+
@callback.call response
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def locationManager(locationManager, didFailWithError: error)
|
32
|
+
response = { error: error }
|
33
|
+
|
34
|
+
@callback.call response
|
35
|
+
stop_updating
|
36
|
+
end
|
37
|
+
|
38
|
+
def location_manager
|
39
|
+
@location_manager ||=
|
40
|
+
begin
|
41
|
+
manager = CLLocationManager.alloc.init
|
42
|
+
manager.desiredAccuracy = self.accuracy ||= KCLLocationAccuracyBest
|
43
|
+
manager.activityType = self.activity_type || CLActivityTypeOther
|
44
|
+
manager.delegate = self
|
45
|
+
manager
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: motion-distance
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Will Raxworthy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Easy distance tracking for iOS RubyMotion projects.
|
28
|
+
email:
|
29
|
+
- git@willrax.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- README.md
|
35
|
+
- lib/motion/distance.rb
|
36
|
+
- lib/motion-distance.rb
|
37
|
+
homepage: ''
|
38
|
+
licenses:
|
39
|
+
- MIT
|
40
|
+
metadata: {}
|
41
|
+
post_install_message:
|
42
|
+
rdoc_options: []
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 2.0.3
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: Easy distance tracking for iOS RubyMotion projects.
|
61
|
+
test_files: []
|