server-side-google-maps 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -131,6 +131,9 @@ module ServerSideGoogleMaps
131
131
 
132
132
  def calculate_distance
133
133
  return GeoMath.latlng_distance(*points) if @direct
134
+ if !leg['distance']
135
+ return leg['steps'].collect{|s| s['distance']}.collect{|d| d ? d['value'].to_i : 0}.inject(0){|s,v| s += v}
136
+ end
134
137
  leg['distance']['value']
135
138
  end
136
139
  end
@@ -1,3 +1,3 @@
1
1
  module ServerSideGoogleMaps
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -54,8 +54,6 @@ module ServerSideGoogleMaps
54
54
  parser = Parser.new(data, :json)
55
55
  parser.parse
56
56
  end
57
-
58
- directions = Directions.new('Montreal,QC', 'Ottawa,ON')
59
57
  end
60
58
 
61
59
  it('should have origin_input and destination_input') do
@@ -118,5 +116,26 @@ module ServerSideGoogleMaps
118
116
  lambda { Directions.new('Montreal,QC', 'Ottawa,ON', :find_shortcuts => { :factor => 0.5, :mode => :direct }) }.should(raise_error(ArgumentError))
119
117
  end
120
118
  end
119
+
120
+ context('when Google forgets the total distance') do
121
+ class Parser < HTTParty::Parser
122
+ public_class_method(:new)
123
+ end
124
+
125
+ before(:each) do
126
+ Directions.stub(:get) do
127
+ data = File.read(File.dirname(__FILE__) + '/files/directions-Montreal,QC-to-Ottawa,ON-without-distance.txt')
128
+ parser = Parser.new(data, :json)
129
+ parser.parse
130
+ end
131
+
132
+ directions = Directions.new('Montreal,QC', 'Ottawa,ON')
133
+ end
134
+
135
+ it('should calculate the distance by summing the parts') do
136
+ directions = Directions.new('Montreal,QC', 'Ottawa,ON')
137
+ directions.distance.should == 199901
138
+ end
139
+ end
121
140
  end
122
141
  end
@@ -0,0 +1,340 @@
1
+ {
2
+ "status": "OK",
3
+ "routes": [ {
4
+ "summary": "Autoroute 40 W and ON-417 W",
5
+ "legs": [ {
6
+ "steps": [ {
7
+ "travel_mode": "DRIVING",
8
+ "start_location": {
9
+ "lat": 45.5086700,
10
+ "lng": -73.5536800
11
+ },
12
+ "end_location": {
13
+ "lat": 45.5062300,
14
+ "lng": -73.5556900
15
+ },
16
+ "polyline": {
17
+ "points": "elwtGn}|_MfNpK",
18
+ "levels": "BB"
19
+ },
20
+ "duration": {
21
+ "value": 20,
22
+ "text": "1 min"
23
+ },
24
+ "html_instructions": "Head \u003cb\u003esouthwest\u003c/b\u003e on \u003cb\u003eRue Notre-Dame E\u003c/b\u003e toward \u003cb\u003ePlace Jacques Cartier\u003c/b\u003e",
25
+ "distance": {
26
+ "value": 313,
27
+ "text": "0.3 km"
28
+ }
29
+ }, {
30
+ "travel_mode": "DRIVING",
31
+ "start_location": {
32
+ "lat": 45.5062300,
33
+ "lng": -73.5556900
34
+ },
35
+ "end_location": {
36
+ "lat": 45.5068900,
37
+ "lng": -73.5572800
38
+ },
39
+ "polyline": {
40
+ "points": "}|vtG`j}_McC|H",
41
+ "levels": "BB"
42
+ },
43
+ "duration": {
44
+ "value": 25,
45
+ "text": "1 min"
46
+ },
47
+ "html_instructions": "Take the 1st \u003cb\u003eright\u003c/b\u003e onto \u003cb\u003eBoulevard Saint-Laurent\u003c/b\u003e",
48
+ "distance": {
49
+ "value": 144,
50
+ "text": "0.1 km"
51
+ }
52
+ }, {
53
+ "travel_mode": "DRIVING",
54
+ "start_location": {
55
+ "lat": 45.5068900,
56
+ "lng": -73.5572800
57
+ },
58
+ "end_location": {
59
+ "lat": 45.5082100,
60
+ "lng": -73.5563400
61
+ },
62
+ "polyline": {
63
+ "points": "aawtG~s}_MgG{D",
64
+ "levels": "BB"
65
+ },
66
+ "duration": {
67
+ "value": 40,
68
+ "text": "1 min"
69
+ },
70
+ "html_instructions": "Take the 1st \u003cb\u003eright\u003c/b\u003e onto \u003cb\u003eRue Saint Antoine E\u003c/b\u003e",
71
+ "distance": {
72
+ "value": 164,
73
+ "text": "0.2 km"
74
+ }
75
+ }, {
76
+ "travel_mode": "DRIVING",
77
+ "start_location": {
78
+ "lat": 45.5082100,
79
+ "lng": -73.5563400
80
+ },
81
+ "end_location": {
82
+ "lat": 45.5071400,
83
+ "lng": -73.5585500
84
+ },
85
+ "polyline": {
86
+ "points": "iiwtGbn}_MuA]g@P}@xBAn@^d@fHnEjAd@",
87
+ "levels": "B???@??B"
88
+ },
89
+ "duration": {
90
+ "value": 61,
91
+ "text": "1 min"
92
+ },
93
+ "html_instructions": "Take the \u003cb\u003eAutoroute 720 O\u003c/b\u003e ramp on the \u003cb\u003eleft\u003c/b\u003e",
94
+ "distance": {
95
+ "value": 404,
96
+ "text": "0.4 km"
97
+ }
98
+ }, {
99
+ "travel_mode": "DRIVING",
100
+ "start_location": {
101
+ "lat": 45.5071400,
102
+ "lng": -73.5585500
103
+ },
104
+ "end_location": {
105
+ "lat": 45.4728800,
106
+ "lng": -73.5967400
107
+ },
108
+ "polyline": {
109
+ "points": "sbwtG|{}_M`TtPjMlIpCnAz@TvJ`@dBXjC`AfBjAfA`AzAtB~@fBr@lBtHhYvClH|DbG~StYrHhLvSj`@|_@~r@lEjErF|BdU`H",
110
+ "levels": "B?@??????@????@??@?@??B"
111
+ },
112
+ "duration": {
113
+ "value": 202,
114
+ "text": "3 mins"
115
+ },
116
+ "html_instructions": "Merge onto \u003cb\u003eAutoroute 720 W\u003c/b\u003e",
117
+ "distance": {
118
+ "value": 5006,
119
+ "text": "5.0 km"
120
+ }
121
+ }, {
122
+ "travel_mode": "DRIVING",
123
+ "start_location": {
124
+ "lat": 45.4728800,
125
+ "lng": -73.5967400
126
+ },
127
+ "end_location": {
128
+ "lat": 45.5019000,
129
+ "lng": -73.6638100
130
+ },
131
+ "polyline": {
132
+ "points": "olptGrje`MPPrD~A|A|AtAhBhAdC~@`Dv@nGFjEIzAg@nDiAnEeFnPsDpKeA~ByKx[uEjKoErIaCdDwGzFaClC{AbCyAjDmJ~WcJrXqItUiFrOOLwWrv@uGlSGp@eDtKqA|CeZbj@QHyG~LqApBuCnD{DjD",
133
+ "levels": "B???@??@????@???@?????@?????????@?????B"
134
+ },
135
+ "duration": {
136
+ "value": 378,
137
+ "text": "6 mins"
138
+ },
139
+ "html_instructions": "Take exit \u003cb\u003e1N\u003c/b\u003e to merge onto \u003cb\u003eAutoroute Décarie/Autoroute 15 N\u003c/b\u003e toward \u003cb\u003eSaint-Jérôme\u003c/b\u003e",
140
+ "distance": {
141
+ "value": 6611,
142
+ "text": "6.6 km"
143
+ }
144
+ }, {
145
+ "travel_mode": "DRIVING",
146
+ "start_location": {
147
+ "lat": 45.5019000,
148
+ "lng": -73.6638100
149
+ },
150
+ "end_location": {
151
+ "lat": 45.5026400,
152
+ "lng": -73.6676900
153
+ },
154
+ "polyline": {
155
+ "points": "{avtGxmr`McAz@uFdDsAlBa@~A@xBXlA\\n@VXl@XzCj@",
156
+ "levels": "B???@??@??B"
157
+ },
158
+ "duration": {
159
+ "value": 30,
160
+ "text": "1 min"
161
+ },
162
+ "html_instructions": "Take exit \u003cb\u003e70O\u003c/b\u003e on the \u003cb\u003eleft\u003c/b\u003e for \u003cb\u003eAutoroute 40 O\u003c/b\u003e toward \u003cb\u003eHull/Ottawa/Autoroute 520/Pierre Elliott Trudeau\u003c/b\u003e",
163
+ "distance": {
164
+ "value": 542,
165
+ "text": "0.5 km"
166
+ }
167
+ }, {
168
+ "travel_mode": "DRIVING",
169
+ "start_location": {
170
+ "lat": 45.5026400,
171
+ "lng": -73.6676900
172
+ },
173
+ "end_location": {
174
+ "lat": 45.5390400,
175
+ "lng": -74.3889100
176
+ },
177
+ "polyline": {
178
+ "points": "ofvtG`fs`MxAp@|AvAjXl^xEfHhAxBxA`Ep@hCl@dDn@bHNvF`@xl@ZvIt@xIfBdLlCfMdA~DtQnz@nAbIl@hG`@~JEpNsIrsDWfOAzN\\tVpB~t@b@pWfAla@d@tHrAfMhBfKlBbIlDzKni@bvAxl@|~A~gAlnCzR|f@pBvGn@lC~AbJjQduAnAdHfBbHrFhOx}@r~BvFlOvAnEfCxIhChKfEpT`J`l@nArGxChMxAlErBzFlG`Od[rs@xRdc@rOf^`C`FhBdFnBpIv@bHT|DPfHMzGeG`hBiCzp@a@xM@bHlQzyEvEpp@vArWnB|UjEpl@l@pGnBtMhD`OrBnGfNl_@vD`Jzh@btA|DzKlGnWjA`JN`GC`Dc@hGiBtI{AzDeC`EcBhBsCbCy@f@k^tYcSnQi{@r_AsChEg@fAgAlCeBhGs@bEc@rEaCzl@_@lTwAb{AWlGiAtKw@rDwChK_p@tvBiB|GwAvIw@xH[`JCvJ~DhhAT|PAhp@YpIuAnSmBxNyLht@iEhRaEbNuBrFgExJ{IpP}d@f~@m`@~p@qL~T}EpM}\\pmAcRnh@gQ`t@uBjLa\\`vCiAfFsAvD}D~GuR|VmR~U{CvF{CpI_Jfh@gL|s@q@xGUvFDbJpOxfDKhGc@`FqBpIwCfGkzA|kBgJvLeg@pr@wC|CkAbAuF~C_DfAgdBbe@mDd@yC?qHo@{C@cEz@wCpA}DdDaE|G{AtEsGj`@",
179
+ "levels": "B??@???@?????@?????A????@???@??A???@?@?????@???@??????@???????A???@???@@???A???@???@???A???@????@@???A??????@??@??@????@???A???@????@??@??@????@??A??@@??A????@???@???@?@?@?B"
180
+ },
181
+ "duration": {
182
+ "value": 2666,
183
+ "text": "44 mins"
184
+ },
185
+ "html_instructions": "Merge onto \u003cb\u003eAutoroute 40 W\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eEntering Ontario\u003c/div\u003e",
186
+ "distance": {
187
+ "value": 66555,
188
+ "text": "66.6 km"
189
+ }
190
+ }, {
191
+ "travel_mode": "DRIVING",
192
+ "start_location": {
193
+ "lat": 45.5390400,
194
+ "lng": -74.3889100
195
+ },
196
+ "end_location": {
197
+ "lat": 45.4124300,
198
+ "lng": -75.6833000
199
+ },
200
+ "polyline": {
201
+ "points": "_j}tGta`eMoRzmAab@vcCu\\|nCuF~]uThiAeE~VyR`wAcSfzA}AjLgA|J[|FK|FTpHp@nIfApGtBxHvBrFfGtIfj@`l@fHjJfGzJhKrV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n}AcFp{@m@vGsAdJoAjGeBxGgCdIop@j_BmBnG}@zDu@vE]zC[~EmIxnBeF|gAiBb\\yBn\\aEne@}e@v_FwBlNiA|EoBvGsBlFyA|CmDfG}OdTgFhI}EnJwKpWkBtDwDnGoGhIeE`EoDvCiHjE{F`CiGhBkHpAyF^}Oj@qC`@kDz@yChAeFtCsNxK_C~AeCrAkE~AqMdDeBx@aBfA{BxBsAfBkCdFoArDcArFk@lGq@zKk@rE}@fEcAdDkBzDqCtD_CpBkBjAgBr@eCn@mM~AqAf@sBnAwBlB{B|C_B`EsA|FS~AYvFDrEZhE^fCrEdRfBdJvA~JjAhMt@vRnEr`Bb@lIXxCh@~CjE|Pd@vCZhDnB`k@ExE{@xLOxEF`GP|Cz@rGpAhFrQdg@rEnQ",
202
+ "levels": "B?@@??@?@???@??A??@??@??@??@?@???@??A?@???@???@????@???@????@???@????@?@??@??@?@???@???A???@??@??@??@?@?@??@??@?A???@???@?@???@????A??@????@???@????A??@??@?@?@??@??@?@????B??????@???????@??@?????A??@????@??@?A????????@????@???@???A???@??@???A??????@????@???@???@??@????@??@????@???@?????@??A???@???????@???@?????@????@???@???@??????@??@????@???A???@????@??@????@?????@???B"
203
+ },
204
+ "duration": {
205
+ "value": 4744,
206
+ "text": "1 hour 19 mins"
207
+ },
208
+ "html_instructions": "Continue onto \u003cb\u003eON-417 W\u003c/b\u003e",
209
+ "distance": {
210
+ "value": 118628,
211
+ "text": "119 km"
212
+ }
213
+ }, {
214
+ "travel_mode": "DRIVING",
215
+ "start_location": {
216
+ "lat": 45.4124300,
217
+ "lng": -75.6833000
218
+ },
219
+ "end_location": {
220
+ "lat": 45.4112800,
221
+ "lng": -75.6874000
222
+ },
223
+ "polyline": {
224
+ "points": "urdtGr{|lMNzAvAjGf@fFtAbF",
225
+ "levels": "B???B"
226
+ },
227
+ "duration": {
228
+ "value": 27,
229
+ "text": "1 min"
230
+ },
231
+ "html_instructions": "Take exit \u003cb\u003e119\u003c/b\u003e for \u003cb\u003eCatherine Street\u003c/b\u003e",
232
+ "distance": {
233
+ "value": 347,
234
+ "text": "0.3 km"
235
+ }
236
+ }, {
237
+ "travel_mode": "DRIVING",
238
+ "start_location": {
239
+ "lat": 45.4112800,
240
+ "lng": -75.6874000
241
+ },
242
+ "end_location": {
243
+ "lat": 45.4088400,
244
+ "lng": -75.6937300
245
+ },
246
+ "polyline": {
247
+ "points": "okdtGfu}lM|@jF`AjDfJxY",
248
+ "levels": "B??B"
249
+ },
250
+ "duration": {
251
+ "value": 108,
252
+ "text": "2 mins"
253
+ },
254
+ "html_instructions": "Slight \u003cb\u003eleft\u003c/b\u003e at \u003cb\u003eCatherine St/Regional Road 60\u003c/b\u003e",
255
+ "distance": {
256
+ "value": 565,
257
+ "text": "0.6 km"
258
+ }
259
+ }, {
260
+ "travel_mode": "DRIVING",
261
+ "start_location": {
262
+ "lat": 45.4088400,
263
+ "lng": -75.6937300
264
+ },
265
+ "end_location": {
266
+ "lat": 45.4125400,
267
+ "lng": -75.6968900
268
+ },
269
+ "polyline": {
270
+ "points": "g|ctGx|~lMU^}ElDoNhL",
271
+ "levels": "B??B"
272
+ },
273
+ "duration": {
274
+ "value": 56,
275
+ "text": "1 min"
276
+ },
277
+ "html_instructions": "Turn \u003cb\u003eright\u003c/b\u003e at \u003cb\u003eKent St/Hwy 17B/Regional Road 83\u003c/b\u003e",
278
+ "distance": {
279
+ "value": 480,
280
+ "text": "0.5 km"
281
+ }
282
+ }, {
283
+ "travel_mode": "DRIVING",
284
+ "start_location": {
285
+ "lat": 45.4125400,
286
+ "lng": -75.6968900
287
+ },
288
+ "end_location": {
289
+ "lat": 45.4119000,
290
+ "lng": -75.6984600
291
+ },
292
+ "polyline": {
293
+ "points": "ksdtGpp_mM~BxH",
294
+ "levels": "BB"
295
+ },
296
+ "duration": {
297
+ "value": 38,
298
+ "text": "1 min"
299
+ },
300
+ "html_instructions": "Turn \u003cb\u003eleft\u003c/b\u003e at \u003cb\u003eJames St\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eDestination will be on the left\u003c/div\u003e",
301
+ "distance": {
302
+ "value": 142,
303
+ "text": "0.1 km"
304
+ }
305
+ } ],
306
+ "duration": {
307
+ "value": 8395,
308
+ "text": "2 hours 20 mins"
309
+ },
310
+ "start_location": {
311
+ "lat": 45.5086700,
312
+ "lng": -73.5536800
313
+ },
314
+ "end_location": {
315
+ "lat": 45.4119000,
316
+ "lng": -75.6984600
317
+ },
318
+ "start_address": "Montreal, QC, Canada",
319
+ "end_address": "Ottawa, ON, Canada",
320
+ "via_waypoint": [ ]
321
+ } ],
322
+ "copyrights": "Map data ©2011 Google",
323
+ "overview_polyline": {
324
+ "points": "elwtGn}|_MfNpKcC|H}IyE}AlEvn@lc@f^pJ|Sbm@fyAndCli@|U~IbSo@dTg\\xaAqb@rp@soAhuDah@t_AeWdXrt@bdA`FlxAn_@jnBsIngFbHdyCxMnp@fuDzoJb^j}B|oAzeD~b@bvBpvAxgDpAd`@oLzqDlQzyEjRtmCzLxn@xcAnlCdJto@oJ|]a|@zt@i{@r_AiJhTsLh`Ei~@bfDrDjbDwSdcBiUzt@weBjfDibAblDab@tjDqs@ldAc\\vgBaAtZpOxfDaD|XuyCp|D}pBjl@y]r@wOtOibC|kO{i@t_EyAjd@fJnc@~cA~mA`e@lxAdX`f@noAbxAjfBbcA~RfUrf@fiCdi@dwAla@`bBpn@t`Bfa@teCzoAnwC~`AxhAtThc@|Inc@tI|uA`Wjz@hu@jdAri@psAja@dn@dc@d]~yArZbc@`W``@~f@tf@dkAjUvjA|FftBxInt@|_BvaG``@tu@bv@ji@dZda@xmAb_EpKniA~DvnDjb@vqErfBtbItMjpAbJb~BsT|{CdL`_C}Bdl@iLpf@iw@noA_K|p@n^n~GkJfsBvHpfBmA~i@sYroAi}@btA}Nrh@yEbhB_b@vdCS~~Ei_AhsJyWzqE_Mhn@qw@ntBqYf~Fmm@tlGqM`d@}aAhcBg`@bVsq@nIc|@bd@sKfR{Lzs@}JrJg\\zIuKjWfOrpAhHx~BpIxd@jA`wAnr@fgCcVvR~BxH",
325
+ "levels": "B@@@@@@@@@A@@@@@A@@A@A@@@@@A@@@A@@B@@@A@@@A@@@@@A@@AA@@A@@B@@@@@@A@@@@@@@@@@A@@@@@@@A@@@A@@@A@@@@@B@@A@@A@@@A@@A@@@@@@@@A@@@@@@@@@A@@@@@@B"
326
+ },
327
+ "warnings": [ ],
328
+ "waypoint_order": [ ],
329
+ "bounds": {
330
+ "southwest": {
331
+ "lat": 45.3026900,
332
+ "lng": -75.6984600
333
+ },
334
+ "northeast": {
335
+ "lat": 45.5655200,
336
+ "lng": -73.5536800
337
+ }
338
+ }
339
+ } ]
340
+ }
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: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Hooper
@@ -82,6 +82,7 @@ files:
82
82
  - server-side-google-maps.gemspec
83
83
  - spec/directions_spec.rb
84
84
  - spec/files/directions-45.5086700,-73.5536800-to-45.4119000,-75.6984600.txt
85
+ - spec/files/directions-Montreal,QC-to-Ottawa,ON-without-distance.txt
85
86
  - spec/files/directions-Montreal,QC-to-Ottawa,ON.txt
86
87
  - spec/files/directions-Ottawa,ON-to-Toronto,ON.txt
87
88
  - spec/route_spec.rb