question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mapbox static API cannot handle polylines with question marks

See original GitHub issue

Hi! 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:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
andrewharveycommented, Apr 29, 2020

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 %3F then the Static API request works.

0reactions
Savio-Fernandes-Gitcommented, Jan 24, 2022

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/500x300

Edit: 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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Static Images | API - Mapbox docs
The Mapbox Static Images API serves standalone, static map images generated from Mapbox Studio styles. These images can be displayed on web and...
Read more >
Mapbox API requests for Static Map and Polyline
I was making two API requests to Mapbox. The first just used coordinates and returned the encoded polyline. The second used the coordinates...
Read more >
Generating Open Graph images with Mapbox & Canvas
It took me a while to figure out that the api does not accept polylines containing question marks "?" as that breaks the...
Read more >
Markers | Maps SDK for Android - Google Developers
... try restarting your device. Your browser can't play this video. ... When you take your finger off the screen, the marker will...
Read more >
Mapbox circle icon
Sign up for free Contact sales. org or a Mapbox API access tokenBootstrap Icons ... typography tagged @mapbox/map-design-team @mapbox/static-apis if this PR ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found