joshuaclayton / polylines

Easily handle Google polylines
MIT License
93 stars 17 forks source link

problem with rounded #3

Closed mdemouchy closed 10 years ago

mdemouchy commented 10 years ago

Hi,

I'm currently using the ruby gem polylines, and thank you for this.

However, I sometime experienced strange behaviour using the gem. Sometimes, I have problems with the output, it seems like there is an issue with rounding when i decode a polyline. If i compare with the array received from the official "Interactive Polyline Encoder Utility", sometimes, I haven't the same result.

https://developers.google.com/maps/documentation/utilities/polylineutility

For example, the string of the polylines used is :

"eyhiHkx}LcGdBGHAFa@WdCeL?IACKOH_@NF?PFqCfE}RTwB?Y|@@v@K`@Yn@oABcAGmAQ{@IiA@cBhGoXtMom@`TyaA^sBB}@Ga@KYMWk@i@y@iAOq@E{ALoB\\eCZwAJF\\uABM^TjLtI`ErCrBtAhAl@l@RTBNCf@]pF{EvMgMjI{Id@[XGxCa@`VyEpHwAtGkA|SyDzCm@X@NFPRnEzFNVJh@@|@oDdPlBpAe@c@D{@^FPH|EhG"

And I linked you 2 screenshots of the results, one with the Google Encoder Utility (on web page), and the other one with the Ruby Gem Polylines (in console).

The item selected on the list of the first screenshot correspond in the second to :

48.87205,2.3006

(rdb:1) array_poly1[25] [48.87205000000001, 2.300600000000001]

As you can see the result seems rounded.

What do you think about that ? Have you ever experienced something similar?

Thank you,

Maxime

decode google utility

decode ruby gem polylines

knarewski commented 10 years ago

This phenomenon is very common when using floats or doubles. According to this: http://www.cjavaphp.com/q/answers-rails-3-float-or-decimal-for-gps-coordinates-11041818.html the difference between values provided by google and gem is negligible (it's not even matter of millimetres), so there is nothing to worry about. From the other hand if you rely on comparing those values, you may need to assume some level of tolerance (i.e. a and b are considered equal if abs(a-b) < tolerance)

joshuaclayton commented 10 years ago

@knarewski thanks for pointing that article out - it's a good read. Closing due to the fact that, while the numbers aren't exact, they're negligible to the point of it not mattering.