basvandorst / StravaPHP

Strava API REST client with OAuth authentication
MIT License
184 stars 67 forks source link

Getting Map via Polyline #14

Closed RichieMcMullen closed 3 years ago

RichieMcMullen commented 8 years ago

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

qligier commented 8 years ago

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

adriangibbons commented 8 years ago

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

adriangibbons commented 8 years ago

@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.
qligier commented 8 years ago

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.

github-actions[bot] commented 3 years ago

Stale issue message