klaxit / fast-polylines

🚀 Fast & easy Google polylines
MIT License
44 stars 13 forks source link

NoMethodError: undefined method `each_byte' for nil:NilClass #9

Closed jsantos closed 4 years ago

jsantos commented 4 years ago

Having the following encoded polyline:

|dae@cs}jSw@Ci@^o@n@q@l@y@Zq@Xw@Xs@Vy@Vu@Vu@Tw@H}@E{@AWv@i@d@s@J}@\\y@Jw@Ju@HmAOu@Po@`@o@^o@\\m@`@q@\\q@b@k@`@u@Ru@Hy@Fy@Ju@Hy@By@Du@Vq@f@Kx@\\n@^l@Zz@N|@?x@`@l@dAH`AB|@Bx@Fz@Rp@Xl@\\n@Et@a@j@o@^s@Z{@Py@Hw@Bw@C}@Ay@Aw@@y@By@Fw@@u@NKv@Bt@|@X|@FbAFv@CVv@?x@Gx@Mx@Wt@u@Hw@c@e@i@e@o@[o@MaAEeA?cALsGz@uKl@_@z@Sp@\\h@n@Rr@Fz@Fz@^n@dAD~@Fz@Dv@Fv@L|@\\t@`@n@\\bATz@?t@A|@@x@Jx@@`@q@b@u@d@y@\\m@\\q@b@o@^m@`@k@`@k@^m@p@_@n@e@l@g@r@g@r@e@|@c@r@Ur@Ux@Wp@Qt@Yz@_@t@[p@Wr@Wh@i@Yq@t@_@`@k@M_AYaAW}@s@mA

The polyline is valid, you can try plotting it on the Interactive Polyline Encoder Utility.

When I try to decode it, I get the following backtrace:

NoMethodError: undefined method `each_byte' for nil:NilClass
from /.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fast-polylines-1.0.0/lib/fast-polylines/decoder.rb:32:in `decode_number'
Caused by NoMethodError: undefined method `each_byte' for nil:NilClass
from /.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/fast-polylines-1.0.0/lib/fast-polylines/decoder.rb:32:in `decode_number'

Anyone has experienced anything similar? Thanks in advance!

rafaeljcadena commented 4 years ago

Same issue here

ccyrille commented 4 years ago

Hi @jsantos @rafaeljcadena , I tested the given polyline against :

So I wonder if the provided polyline is in fact invalid even if it returns a result for some implementations. Could you give me the original coordinates that generated this polyline ?

jsantos commented 4 years ago

@ccyrille I have to dig a bit to fetch the original data, but will post it here as soon as I can. Thanks a lot!

democlitos commented 4 years ago

@ccyrille It seems to be related to the double backslash. If you compare both responses (fast-polylines 2.x and IPE utility) you will notice that the result is the same until the occurrence of the first double backslash.

democlitos commented 4 years ago

@jsantos @ccyrille Yeah, it is related to the double backslash. If for every double backslash I add one more:

|dae@cs}jSw@Ci@^o@n@q@l@y@Zq@Xw@Xs@Vy@Vu@Vu@Tw@H}@E{@AWv@i@d@s@J}@\\\\y@Jw@Ju@HmAOu@Po@`@o@^o@\\\\m@`@q@\\\\q@b@k@`@u@Ru@Hy@Fy@Ju@Hy@By@Du@Vq@f@Kx@\\\\n@^l@Zz@N|@?x@`@l@dAH`AB|@Bx@Fz@Rp@Xl@\\\\n@Et@a@j@o@^s@Z{@Py@Hw@Bw@C}@Ay@Aw@@y@By@Fw@@u@NKv@Bt@|@X|@FbAFv@CVv@?x@Gx@Mx@Wt@u@Hw@c@e@i@e@o@[o@MaAEeA?cALsGz@uKl@_@z@Sp@\\\\h@n@Rr@Fz@Fz@^n@dAD~@Fz@Dv@Fv@L|@\\\\t@`@n@\\\\bATz@?t@A|@@x@Jx@@`@q@b@u@d@y@\\\\m@\\\\q@b@o@^m@`@k@`@k@^m@p@_@n@e@l@g@r@g@r@e@|@c@r@Ur@Ux@Wp@Qt@Yz@_@t@[p@Wr@Wh@i@Yq@t@_@`@k@M_AYaAW}@s@mA

Then the results from the version 2.x and google IPE are exactly the same.

BuonOmo commented 4 years ago

@democlitos I've tried your polyline, and the results are quite similar. However, IPE add a trailing @ to the polyline. I had to add it as well to get the same result (otherwise there was a missing coordinate).

In the end, both results are identical. I'll close this issue, please open a new one if you have a similar issue. And please also provide us the original coordinates alongside the wronged polyline 🙂