Mapbox static API cannot handle polylines with question marks
See original GitHub issueHi! I know this is not a bug with polyline per se, but I am unsure where to open an issue for this.
I am using the Mapbox static API (https://docs.mapbox.com/api/maps/#static-images) which supports polylines as overlay.
However, sometimes my polyline contains question marks (the ? character), and it seems that the static API interprets this as the beginning of the query parameters and fails to parse a token.
One example is this one:
https://api.mapbox.com/styles/v1/mapbox/satellite-v9/static/path-4+DAF34E(_vztHoqk%5CiNnLsBaI%60FaE?g@%60DmBIi@zC%7DAfApJ)/4.814415,50.770556,14/200x220?access_token=ACCESS_TOKEN_HERE
This polyline was encoded with @mapbox/polyline, but the query responds with a 401 unauthorized as the access token is not parsed.
Are polylines allowed to have this character ? If yes, is it an issue with the static API url parser?
I’d be happy to help dig into this if needed. Thanks!
Issue Analytics
- State:
- Created 3 years ago
- Comments:6

Top Related StackOverflow Question
According to the polyline spec https://developers.google.com/maps/documentation/utilities/polylinealgorithm
?is the first possible character, since 0 + 63 is the?char in ASCII, so?is valid to appear in the encoding.Based on that, there is no issue with this library itself.
For the second issue, which is unreleated to this library, if you replace the
?with the escaped character%3Fthen the Static API request works.Hi @andrewharvey, I replaced ‘?’ with ‘%3F’ however get a 404 error on doing so. Following is the Uri without the access token
https://api.mapbox.com/styles/v1/mapbox/streets-v11/static/path-5+f44-0.5(mu~qDqrjdHy@aBWi@i@eAgBmD_AmB%3FI%3FE%3FG%3FGBEBInCiB|AmA@AJGzCcCHEDCDAFAD%3FF%3FF@DBRPb@pBx@tCb@tAj@dBTl@RRLDR@LGHGJQBQ%3Fa@kCuH_AoD_A}Dc@yAi@aE]gC[cDYwDSkDAIEuAE_B%3F_D%3Fg@DWHk@h@e@Xo@Ju@Cu@Ss@Q[WU]Oa@IS%3FY@[Hc@V]b@Sj@Ep@%3FPB\\@^C^I\\]^sBzBaAlAwBpCW\\o@z@}@nA}BpDuAbC)/auto/500x300Edit: Found a solution Pass your Uri using Uri.EscapeDataString(<uri>); This will take care of non-Uri-friendly characters and convert them.
https://stackoverflow.com/questions/86477/does-c-sharp-have-an-equivalent-to-javascripts-encodeuricomponent