Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok, so I think I figured it out. Many thanks to <a href="https://stackoverflow.com/users/1204258/andrew-leach">Andrew Leach</a> for explaining how the algorithm actually works in plain english.</p> <p><strong>Problem:</strong> Merging a new encoded polyline with an existing encoded polyline</p> <p><strong>Solution:</strong> keep last coord pair from existing polyline, encode just that pair and save it for later, encode all new coords with coord from existing polyline at the beginning of this new encoding. find the string of the last coordinate pair, and remove it from the new encoded polyline and stick the new encoded polyline onto the back of the existing polyline</p> <p><strong>Things to know:</strong> What the encoding does is calculate the offset (distance from x,y) and converts that value to ASCII. The problem is the first coordinate is calculated from 0,0 so if you were just to put two encoded polylines together, where you added the new one wouldn't be offset from the existing, but offset from 0,0 causing a large jump in the polyline. What we need to do is find out which characters in the encoded polyline are the offset from 0,0 and remove them. Then you can append the new line to the old line, and it will be offset properly.</p> <p>Click the link below to see it all written up and with good comments. Also, please let me know if you see anywhere the efficiency can be improved!</p> <p><a href="http://pastebin.com/b0HKkpM6" rel="nofollow noreferrer">PasteBin: PHP implementation of solution</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload