I had the same problem as you (also trying to get elevation data for Strava segment polylines) and solved by making a request to Google's Elevation service using their elevation javascript API.
If you want to use Google's service, you'll need to sign up (for free unless you're making lots of requests) to Google's maps service to get an API key and then reference their js file:
<script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY">
</script>
Then get your decoded polyline from Strava, pull out the coordinates and request the elevation for the coordinates from Google. This is what I did:
/*
Get your decoded polyline from Strava (formatted as follows)
[
{
"latitude": 55.13186,
"longitude": -6.0442
},
{
"latitude": 55.13202,
"longitude": -6.04401
}
]
*/
const segmentCoordinates = segmentPolylineDecoded;
// Change polyline into correct format for request to Google
let routeCoordinatesInCorrectFormat = segmentCoordinates.map(function(x) {
return { lat: x.latitude, lng: x.longitude };
});
let elevationData;
const elevator = new google.maps.ElevationService();
elevator
.getElevationAlongPath({
path: routeCoordinatesInCorrectFormat,
samples: 256,
})
.then(({ results }) => {
elevationData = results;
plotElevation();
})
.catch((e) => {
// error
});
The response from Google comes back in the following format:
[
{
"elevation": 14.16793346405029,
"location": {
"lat": 55.13186,
"lng": -6.0442
},
"resolution": 610.8129272460938
},
{
"elevation": 14.90726280212402,
"location": {
"lat": 55.1321392922906,
"lng": -6.043826473467345
},
"resolution": 610.8129272460938
}
]