Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Encode locations as a single string in the Google polyline format
ResourceFunction["GooglePolylineEncode"][loc] returns the polyline encoding string of location loc. | |
ResourceFunction["GooglePolylineEncode"][GeoPosition[{lat,lon}]] returns the polyline encoding string of the GeoPosition with latitude lat and longitude lon. | |
ResourceFunction["GooglePolylineEncode"][{lat,lon}] returns the polyline encoding string of the position with latitude lat and longitude lon. | |
ResourceFunction["GooglePolylineEncode"][locs] returns the polyline encoding string of the list of positions locs. |
Find the polyline string for New York City:
In[1]:= | ![]() |
Out[1]= | ![]() |
Find the polyline string for a RandomGeoPosition:
In[2]:= | ![]() |
Out[2]= | ![]() |
In[3]:= | ![]() |
Out[3]= | ![]() |
Use the latitude and longitude (as quantities) instead:
In[4]:= | ![]() |
Out[4]= | ![]() |
In[5]:= | ![]() |
Out[5]= | ![]() |
Use real numbers for the latitude and longitude:
In[6]:= | ![]() |
Out[6]= | ![]() |
In[7]:= | ![]() |
Out[7]= | ![]() |
A list of locations is more commonly used to indicate geographic routes:
In[8]:= | ![]() |
Out[8]= | ![]() |
In[9]:= | ![]() |
Out[9]= | ![]() |
The polyline encoding of a route is not simply StringJoin of the polyline encoding of each individual location, due to the use of coordinate offsets:
In[10]:= | ![]() |
Out[10]= | ![]() |
Find the polyline encoding of a list of RandomGeoPositions:
In[11]:= | ![]() |
Out[11]= | ![]() |
In[12]:= | ![]() |
Out[12]= | ![]() |
Integer values of latitude and longitude may be used:
In[13]:= | ![]() |
Out[13]= | ![]() |
If one of the coordinates is zero, this is indicated by a '?':
In[14]:= | ![]() |
Out[14]= | ![]() |
In[15]:= | ![]() |
Out[15]= | ![]() |
In[16]:= | ![]() |
Out[16]= | ![]() |
In[17]:= | ![]() |
Out[17]= | ![]() |
GooglePolylineEncode can encode latitudes and longitudes of up to five decimal places. Often, GeoPosition objects are displayed with fewer decimal places than this. If one simply copies and pastes the displayed latitude and longitude values returned by GeoPosition, a disagreement may occur between the output of GooglePolylineEncode and this website. Pasting the FullForm of the latitude and longitude ensures agreement with the site:
In[18]:= | ![]() |
Out[18]= | ![]() |
In[19]:= | ![]() |
Out[19]= | ![]() |
In[20]:= | ![]() |
Out[20]= | ![]() |
Encode a list of coordinates representing a hike up Scafell Pike, Lake District, UK:
In[21]:= | ![]() |
In[22]:= | ![]() |
Out[22]= | ![]() |
In[23]:= | ![]() |
Out[23]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License