Polylines for a route via the REST API

90 views
Skip to first unread message

Brandon Perdue

unread,
Aug 16, 2021, 9:07:37 PM8/16/21
to onebusaway-developers
I'm trying to add a map to all of our route pages on our site and I'm running into some issues. 

How do you get the polylines for a specific route?  I've been using the stops-for-route endpoint and showing the polylines that are in the StopGroups, but it only partially works.  Half of our routes show correct but some have the lines running way off.  I thought our initial data may be wrong so I compared what the Android app is showing to what my test script is displaying on a map and they were different.  The Android app looked fine and only has the actual route shown. 

Is there some other place to get that data?  Where is the Android app getting it from?

Sean Barbeau

unread,
Aug 17, 2021, 3:06:28 PM8/17/21
to onebusaway-developers

Brandon Perdue

unread,
Aug 18, 2021, 3:13:39 PM8/18/21
to onebusaway-developers
The includePolylines=true is on by default, but just to be sure I tried it with it there and it didn't change anything.  Looking at the android code I see that it is pulling in the shapes from the data.entry.polylines element in the response (https://github.com/OneBusAway/onebusaway-android/blob/80893c93652d98cb053441b4b620052b0f9899b9/onebusaway-android/src/main/java/org/onebusaway/android/io/request/ObaStopsForRouteResponse.java#L88).  Right now I'm adding both those and the stopgroup polylines just to be sure I'm not missing anything and it is off.  We are seeing a lot of extra lines but also some missing.  The screen grab below is actually one of the better ones, but it still has a random line going south and doesn't have the full loop on the left hand side.  Others are missing way larger chunks of data.


Screenshot 2021-08-18 at 11-47-50 SCC - Spokane Transit Authority.png

Brandon Perdue

unread,
Aug 19, 2021, 2:51:59 PM8/19/21
to onebusaway-developers

I finally figured this out.  In case anybody else runs into this, the issue was with escape characters in the polyline data.  PHP was automatically converting \\ to \ and that was making subtle changes to the polyline when I decoded and added it to the map.  Doing a simple str_replace("\\","\\\\", $polyline) when I added the polyline to the JS for the map fixed it.

Sean Barbeau

unread,
Aug 19, 2021, 3:06:36 PM8/19/21
to onebusaway-developers
Thanks, good to know!

Sean

Reply all
Reply to author
Forward
0 new messages