Since this is a language agnostic question, I will add this PHP solution (since the >>> operator does not exist in PHP) from the Peter Chng unitstep blog :
function decodePolylineToArray($encoded) { $length = strlen($encoded); $index = 0; $points = array(); $lat = 0; $lng = 0; while ($index < $length) { $b = 0; $shift = 0; $result = 0; do { $b = ord(substr($encoded, $index++)) - 63; $result |= ($b & 0x1f) << $shift; $shift += 5; } while ($b >= 0x20); $dlat = (($result & 1) ? ~($result >> 1) : ($result >> 1)); $lat += $dlat; $shift = 0; $result = 0; do { $b = ord(substr($encoded, $index++)) - 63; $result |= ($b & 0x1f) << $shift; $shift += 5; } while ($b >= 0x20); $dlng = (($result & 1) ? ~($result >> 1) : ($result >> 1)); $lng += $dlng; $points[] = array($lat * 1e-5, $lng * 1e-5); } return $points; }
Additional instructions from Google developers
Update: The decoding instructions are almost simple, to find the original value, you can calculate whether it is the positive or negative last bit for each value that you have already converted from your ASCII characters.
Example:
Step 5. If your value, broken into pieces (pieces 5), has the last bit "0x1f", then this is negative, and you should invert it as in: |= ($foo & 0x1f) << $shift;
00000010 00100101 01000011 11100001
4 Double-shift the binary value:
11111101 11011010 10111100 00011110
3 Convert the binary value to decimal, remember, if you understand that it is a negative number, then you must convert it from two additions, Two additions : if it was positive, just convert the binary file as usual:
11111110 11101101 01011110 00001111
11111110 11101101 01011110 00001110
00000001 00010010 10100001 11110001 <- our initial value is unsigned
2 The decimal value was multiplied by 1e5, so divided it to get the initial value: 179.98321
1 Add the original value of your character (if necessary) -179.98321 (this is a bit of data loss, but its rather inappropriate)