I’ve talked about the Google Maps encoded polyline format before. While there’s some nice utilities for encoding polylines that take the work out of implementing it yourself, I couldn’t find many polyline decoders.
This made it somewhat tedious to decode them, as the only way to get the original list of points was to create a
Since the encoded polyline format offers numerous benefits (and because I had data already stored in this format) I did not want to move away from it. At the same time, I needed access to the points for working with things like Google Static Maps, which curiously does not accept the encoded polyline format for displaying paths. (Probably to reduce resource usage on their end, since decoding takes CPU time)
Thankfully the polyline decoding algorithm was already available at Mark McClure’s site. I spent a few minutes understanding the process and porting it over to PHP. The source is attached above and is released under an MIT license. Basically, the only change I had to make was to use some PHP functions to convert characters to their ASCII code, since PHP doesn’t have a
Please let me know if you find it to be useful.