basvandorst/StravaPHP

Getting Map via Polyline

RichieMcMullen opened this issue · 5 comments

Having trouble displaying the map using the Polyline code retrieved from the activity object. Any ideas on how to display it (PHP or JS) ?

You can use the Polyline Encoder library to decode the Polyline field. It returns the coordinates of each points.
Edit: fixed link

Hi @qligier, the URL in your post doesn't go anywhere. I think you mean Polyline Encoder, which I have used and is excellent.

Btw, PHP-Geometry contains a nice implementation of the Ramer–Douglas–Peucker algorithm. This gives you a similar looking line from fewer points.

Instead of decoding the polyline into lat-lngs at the server side, you could do this in the browser if you use Leaflet maps through the Leaflet.encoded plugin. Other maps have similar functionality too :)

@richtt a couple of issues I have bumped into with encoded polylines:

  1. If you pass the encoded polyline as part of browser URL, remember that you should limit the overall URL length to 2,000 characters - this can be an issue for encoded polylines that represent thousands of lat-lngs.
  2. Escaping of special characters in encoded polylines. I've seen at least backslashes and have used PHP's addslashes and stripslashes to remedy things, particularly if you're storing/retrieving from a database.

Yes, sorry for the link. I only knew the older google-map-polyline-encoding-tool and I've changed it just before sending the message.
The Leaflet.encoded plugin seems a very good alternative.

Stale issue message