server-side-google-maps 0.2.2 → 0.2.3
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.
@@ -20,11 +20,17 @@ module ServerSideGoogleMaps
|
|
20
20
|
# Returns a new Path with n equidistant Points along this Path, complete with .elevation
|
21
21
|
def elevations(n)
|
22
22
|
results = self.class.get_elevations(:path => "enc:#{encoded_path}", :samples => n)
|
23
|
+
|
24
|
+
i = -1
|
25
|
+
total_distance = points.last.distance_along_path
|
26
|
+
|
23
27
|
points = results['results'].collect do |r|
|
28
|
+
i += 1
|
24
29
|
Point.new(
|
25
30
|
r['location']['lat'].to_f,
|
26
31
|
r['location']['lng'].to_f,
|
27
|
-
:elevation => r['elevation'].to_f
|
32
|
+
:elevation => r['elevation'].to_f,
|
33
|
+
:distance_along_path => total_distance && (total_distance.to_f * i / (n - 1)).to_i
|
28
34
|
)
|
29
35
|
end
|
30
36
|
Path.new(points)
|
data/spec/path_spec.rb
CHANGED
@@ -54,6 +54,17 @@ module ServerSideGoogleMaps
|
|
54
54
|
elevations.points[0].longitude.should == -73.55368
|
55
55
|
elevations.points[19].elevation.should == 89.6621323
|
56
56
|
end
|
57
|
+
|
58
|
+
it('should populate #distance_along_path') do
|
59
|
+
pt1 = Point.new(45.50867, -73.55368)
|
60
|
+
pt2 = Point.new(43.65235, -79.38240)
|
61
|
+
path = Path.new([pt1, pt2])
|
62
|
+
path.calculate_distances
|
63
|
+
elevations = path.elevations(20)
|
64
|
+
elevations.points[0].distance_along_path.should == 0
|
65
|
+
elevations.points[19].distance_along_path.should == path.points.last.distance_along_path
|
66
|
+
elevations.points[9].distance_along_path.should == (path.points.last.distance_along_path * 9.0 / 19).to_i
|
67
|
+
end
|
57
68
|
end
|
58
69
|
end
|
59
70
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: server-side-google-maps
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Adam Hooper
|