gpsutils 0.1.2 → 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/README.md +18 -0
- data/lib/gpsutils/version.rb +1 -1
- data/lib/gpsutils.rb +28 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e410d5e1e4435cecaae8722bc66b90d596289587
|
4
|
+
data.tar.gz: 439be1ddb2aaf0cc434337df87332f8f770379da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9cc43650c648ca115506597522fe6360a588c58fb02f63373e724d6a23db521dfbbec713b3b6c101a5948c2cdfbaef141b9b97a0cf0c839d9f984fdfad706047
|
7
|
+
data.tar.gz: b8f4e2253be54e8fb2c8d32d4ac4dfd18cb64434af0915570c328bd3ba764b5e8b281f79ff3a62bd5861ae82ec1d0381f0e82ef4b37e0ea9e6315503764c804d
|
data/README.md
CHANGED
@@ -89,5 +89,23 @@ area = GpsUtils::BoundingBox.new(nw, se)
|
|
89
89
|
area.cover? location
|
90
90
|
```
|
91
91
|
|
92
|
+
Sort positions (Points) by distance to location (Point):
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
# Follow instructions in the installation section.
|
96
|
+
require 'gpsutils'
|
97
|
+
|
98
|
+
# Latitude, Longitude.
|
99
|
+
location = GpsUtils::Point.new(-22.955776, -43.536438)
|
100
|
+
|
101
|
+
positions = []
|
102
|
+
positions.push(GpsUtils::Point.new(-23.560112, -46.642043))
|
103
|
+
positions.push(GpsUtils::Point.new(-12.994417, -38.508040))
|
104
|
+
|
105
|
+
positions.sort_by! do |position|
|
106
|
+
location.distance(position)
|
107
|
+
end
|
108
|
+
```
|
109
|
+
|
92
110
|
## License
|
93
111
|
This code is free to use under the terms of the [MIT license](LICENSE).
|
data/lib/gpsutils/version.rb
CHANGED
data/lib/gpsutils.rb
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
module GpsUtils
|
2
|
+
R = 6371e3
|
3
|
+
|
4
|
+
def self.to_radians(degrees)
|
5
|
+
degrees * Math::PI / 180
|
6
|
+
end
|
2
7
|
|
3
8
|
class Point
|
4
9
|
# @!attribute [r] lat
|
@@ -35,6 +40,29 @@ module GpsUtils
|
|
35
40
|
def to_s
|
36
41
|
"#{@lat},#{@lng}"
|
37
42
|
end
|
43
|
+
|
44
|
+
# Measure the distance between this point and another.
|
45
|
+
#
|
46
|
+
# Distance is calculated using equirectangular projection.
|
47
|
+
# @see https://en.wikipedia.org/wiki/Equirectangular_projection
|
48
|
+
#
|
49
|
+
# @param other [Point]
|
50
|
+
# @return [Float]
|
51
|
+
# @raise [ArgumentError] if other is not a Point
|
52
|
+
def distance(other)
|
53
|
+
unless other.is_a? Point
|
54
|
+
raise ArgumentError.new 'other must be a Point.'
|
55
|
+
end
|
56
|
+
|
57
|
+
dlng = GpsUtils::to_radians(other.lng - @lng)
|
58
|
+
dlat = GpsUtils::to_radians(other.lat - @lat)
|
59
|
+
|
60
|
+
x = dlng * Math.cos(dlat / 2)
|
61
|
+
y = GpsUtils::to_radians(other.lat - @lat)
|
62
|
+
|
63
|
+
Math.sqrt(x**2 + y**2) * GpsUtils::R
|
64
|
+
end
|
65
|
+
|
38
66
|
end
|
39
67
|
|
40
68
|
class BoundingBox
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gpsutils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ronnie Mose
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|