Function Repository Resource:

GooglePolylineDecode

Source Notebook

Decode Google polyline strings into coordinate locations

Contributed by: Joseph Brennan

ResourceFunction["GooglePolylineDecode"][str]

decodes the polyline string str and returns the corresponding GeoPosition(s).

Details

Polyline encoding is a lossy compression algorithm that represents a series of coordinates as a single string of ASCII characters. This function does the inverse.
ResourceFunction["GooglePolylineDecode"] returns valid locations as GeoPosition objects, in a latitude range of -90° to +90° and a longitude range of -180° to +180°.
ResourceFunction["GooglePolylineDecode"] returns latitudes and longitudes correct to five decimal places, which corresponds to about 1m at the equator.

Examples

Basic Examples (2) 

Decode a polyline string representing a single location:

In[1]:=
ResourceFunction["GooglePolylineDecode"]["wb}cHften`@"]
Out[1]=

Decode a polyline string representing a route containing many locations:

In[2]:=
ResourceFunction[
 "GooglePolylineDecode"]["pgwYnajqF}dn`@{bshMfnokBjzoed@vgmkBeys_]ryU|vkz`@"]
Out[2]=

Scope (2) 

The "?" character indicates a zero value for latitude/longitude:

In[3]:=
ResourceFunction["GooglePolylineDecode"]["wzzvI?"]
Out[3]=
In[4]:=
ResourceFunction["GooglePolylineDecode"]["?_zlnC"]
Out[4]=
In[5]:=
ResourceFunction["GooglePolylineDecode"]["??"]
Out[5]=

If the polyline string contains information for only one coordinate, a single number is returned:

In[6]:=
ResourceFunction["GooglePolylineDecode"]["mgjjA"]
Out[6]=

Applications (1) 

Make a GeoGraphPlot of a decoded route:

In[7]:=
locs = ResourceFunction["GooglePolylineDecode"][
  "ckqgGnrcwRgxfxAefluOdppdUjxen]u~{rEujdyPgyqmJghvgT"]
Out[7]=
In[8]:=
route = MapThread[Rule[#1, #2] &, {Most[locs], Rest[locs]}];
GeoGraphPlot[route, DirectedEdges -> True]
Out[5]=

Possible Issues (3) 

If a polyline is incomplete, i.e. the number of latitudes and longitudes are unequal, an error is returned:

In[9]:=
ResourceFunction["GooglePolylineDecode"]["{zegDo~lnHwprwD"]

The following completes the polyline above by including a second latitude:

In[10]:=
ResourceFunction["GooglePolylineDecode"]["{zegDo~lnHwprwD|cbqS"]
Out[10]=

If a polyline is insufficient to express a coordinate, the same error is returned:

In[11]:=
ResourceFunction["GooglePolylineDecode"]["{ze"]

If a polyline is incomplete but the 'remainder' after the complete section of the string is insufficient to express a coordinate, the locations of the complete section are returned:

In[12]:=
ResourceFunction["GooglePolylineDecode"]["{zegDo~lnHwpr"]
Out[12]=

Neat Examples (1) 

Decode a polyline representing a hike up Scafell Pike, Lake District, UK:

In[13]:=
coords = ResourceFunction["GooglePolylineDecode"][
   "edlkIxfzRfB[|G@PXrAId@Z|DgApGY|B_B`Bg@h@s@lC]`@g@d@cCGoPq@uC{@}AcAcHMoHrAmEAqFz@_M\\u@_@cABcApCwKh@{D\\oFK{BkAwGcAkKoBmGaAoKiBuEe@?QyAeA^[sBkBLAgCm@CIW]iFuAsCs@oG?sBv@cCj@IJe@XA~DwDjAdCpAn@`@wB|@}@^kE~AsGBeCrA_INkEXm@`@@RYSuF_A_BuCmAeDgCdDfCtClA~@~ARtFSXa@AYl@OjEsA~HCdC_BrG_@jE}@|@a@vBqAo@kAeC_EvDY@Kd@k@Hu@bCc@Ie@^mAnBg@|FPjC`@\\mC~JBpAjAbEp@xL[vIPbCWjLmAdJc@fKh@tQx@|GTxGj@tAIp@~AnBN`A`AN|AjGtD`In@jCpAnA|C~F~B`Ja@f@mC\\i@r@aBf@}B~AqGX}DfAe@[sAHQY}GAoAZcAMkAvHuBvFkBnIgAu@qDY_Ff@yAw@eBK[t@]C"];
GeoListPlot[coords, Joined -> True, GeoBackground -> "Satellite"]
Out[10]=

Publisher

Joseph Brennan

Version History

  • 1.0.0 – 20 August 2025

Source Metadata

Related Resources

License Information