I’ve found this well-referenced page Encoding polylines for Google Maps. I’ve implemented their algorithms for encoding and decoding polylines in my application, but I’m facing some issues keeping the precision of the coordinates.
I’ve these coordinates for my polyline:
57.012415241636155, 9.99178024863532
57.012422477487256, 9.991334773101812
57.01190974033057, 9.99068645350514
If I encode them using their encoder I get this encoded polyline:
qf~zIso~{@AxAfB`C
If I afterwards try to decode this encoded string using their decoder I get these coordinates:
57.01241, 9.99178
57.012420000000006, 9.991330000000001
57.011900000000004, 9.990680000000001
Why am I losing the precision of my coordinates? I need my encoded polyline to be more precise.
You are losing precision because encoding does that.
However, you most certainly do not need that precision. The distance between (57.012410, 9.991780) and (57.012411, 9.991781) — 1 at the sixth decimal place — is 12cm. Each digit at the fifth decimal place will be about a metre. The maps aren’t that accurate.