NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

I must understand how encode polyline algorithm works and I follow this link:

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

but I don't understand the 8 points?

  • 7)Place the 5-bit chunks into reverse order: 00001 11111 10000 01010 00010 00001
  • 8)OR each value with 0x20 if another bit chunk follows: 100001 111111 110000 101010 100010 000001

what do you mean?

asked 22 Oct '14, 18:16

scupetta18's gravatar image

scupetta18
-3111115
accept rate: 0%

edited 23 Oct '14, 13:34

aseerel4c26's gravatar image

aseerel4c26 ♦
32.6k18248554


I'm assuming that you understand points 1-6; please say if not.

Point 7 means that you reverse the order of the bytes. In other words, the last should be first, the second-to-last should be second, and so on. A B C D E becomes E D C B A.

Point 8 means that you add 32 (the decimal representation of 0x20, which is a hex value) to all but the last value. This is used as a signal for 'another value follows'.

For most languages, there is a ready-made polylines library that you can use, so you don't have to worry about the intricacies of encoding/decoding yourself. For Ruby: https://github.com/joshuaclayton/polylines. For JavaScript using Leaflet: https://github.com/jieter/Leaflet.encoded.

permanent link

answered 23 Oct '14, 07:57

Richard's gravatar image

Richard ♦
30.9k44279412
accept rate: 18%

This is an OpenStreetMap help forum. The Google polyline encoding algorithm is not on topic here even if it should be used by some software in conjunction with OSM. GIS Stack Exchange might be a better place to ask your question.

permanent link

answered 22 Oct '14, 18:40

Frederik%20Ramm's gravatar image

Frederik Ramm ♦
82.5k927201273
accept rate: 23%

2

It's perfectly on topic. Being able to work with the "Google polyline" algorithm is essential for the most popular OSM-based routing software. You may as well close down any questions about tile URLs because the scheme we use for that, too, was invented by Google.

(23 Oct '14, 07:46) Richard ♦

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×85
×8
×8

question asked: 22 Oct '14, 18:16

question was seen: 6,978 times

last updated: 23 Oct '14, 13:34

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum