I'm trying to draw an encoded polyline via the Google Maps API (v3), and it seems to draw 'sort of' correctly (as in, roughly in the right area of the world ;) ) but otherwise is very, very wrong. (Pictures to follow)

Essentially, I'm using the Strava API (v3) to get road 'segments', which include encoded polylines (http://strava.github.io/api/#polylines). The short version is, I'm decoding these as per the Google documentation and then creating a new Polyline object with the new path and adding it to the map.

I've been very brief in summing up that part, simply because my method doesn't seem to be the issue here... If I take the encoded polyline string directly from the response of the API call and paste it into Google's Interactive Polyline Encoder Utility (https://developers.google.com/maps/documentation/utilities/polylineutility) I see the same 'wrong' path.

So, that leaves two possibilities... Either the Strava API is passing out incorrect data, or I'm not correctly understanding what I'm supposed to do with it.

I've attached the relevant images + polyline below. Am I doing something obviously wrong?

Example 'encoded' polyline:


Strava map (correct):

Strava (Correct)

Decoded polyline (wrong):

Decoded polyline (WRONG)

3 Answers 3


Ah.. rookie mistake...

The response included escaped backslashes facepalm. After removing those, it's all good.

  • 1
    Got caught by the same, I was pasting a string with backslashes too, interesting though that the linestring gets drawn around where it should be.
    – nevi_me
    Commented Jan 21, 2017 at 18:28

If anyone comes across this while working with ruby/rails this is what I had to do to get the correctly formatted string for javascript:


then in view inside the javascript tag where I setup the map (or perhaps in a js asset file depending how you choose to structure your app):

var decodedPath = google.maps.geometry.encoding.decodePath('<%= @polyline.gsub("\\", "\\\\\\\\") %>');

Wasted much time on this. It looks wrong to me (thought it would be half the number of backslashes) but it was the only thing that worked for me. Hope it helps.


Just replace "\\" by "\"

For instance:



  • Thx, it's helped alot with ST_LineFromEncodedPolyline in postgis Commented Feb 2, 2022 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.