NEW UPDATE: New function to encode into a string a point with latitude and longitude!
Hello Makers! Here I present to you my first extension ever made for decoding and encoding polylines from Google Maps API. First, I found the Encoding Polyline Algorithm Format and tried to reverse it using blocks, but then I found the Jeffrey Sambells’ method and I felt like learning how to make an extension.
So this is it! I hope you find this useful and if you find how to make it better, please let me know so I can learn from it.
This extension was made in colaboration with Diego Pedroza.
Tool developed by Carlos Pedroza to decode and encode Polylines from Google Maps API based on Jeffrey Sambells’ method and Sciolist’s method.
Decode: Decodes polyline and returns a list of paired lat/lng, based on Jeffrey Sambells’ method.
EncodeLatORLng: Encodes ONLY ONE number lat or lng into a string following the Encoding Polyline Algorithm Format, based on Sciolist’s method.
EncodePoint: Encodes a point with latitude and longitud in a list into a string following the Encoding Polyline Algorithm Format, based on Sciolist’s method.
In order to test it, this example encodes a list with one point latitude and longitud and later it decodes it back.
The reason why I had incorrect decoding and encoding it was because I wasn’t paying attention to an instruction from Encoding Polyline Algorithm Format.
Additionally, to conserve space, points only include the offset from the previous point (except of course for the first point).
That’s why I couldn’t just join every step in a single string and then decode it, or encode each point without encoding only the offset.
I figured how to use at some point YailLists but I haven’t figured out how to manage a list of a list (list of paired lat/lng). It is homework! But, meanwhile, here I present a workaround that works:
- Video tutorial
Best Regards from ,