简体   繁体   中英

Strava API - accurate longitude and latitude

Does anyone know a way to get the exact longitude and latitude for an activity from the strava api using a get request?

I'm trying to integrate the strava api with google maps and I'm trying to build an array with the appropriate long/lat locations, but the https://www.strava.com/api/v3/athlete/activities?per_page=100... request is only returning longitude and latitudes rounded off like: start_longitude: 2.6 .

I've found a "hacky" way of retrieving the start coordinates by looping through results and then sending off another request within the loop, although this is sending WAY too many requests. - below is a snippet of my request:

// start request
$.get( "https://www.strava.com/api/v3/athlete/activities?per_page=100&access_token=ACCESSTOKEN", function (results) {

    // loop through request
    for (i = 0; i < results.length; i++) {

        if(results[i].type === 'Run') {
            // add an element to the array for each result
            stravaComplete.push(true);

            $.get( "https://www.strava.com/api/v3/activities/"+ results[i].id +"?per_page=5&access_token=ACCESSTOKEN", function (runs) {
                 if(typeof runs.segment_efforts[0] != "undefined"){
                    var runLatitude = runs.segment_efforts[0].segment.start_latitude;
                    var runLongitude = runs.segment_efforts[0].segment.start_longitude;
                    stravaActivityList.push({"lat": runLatitude, "lng": runLongitude});
                 }

                 // remove the element from the array
                 stravaComplete.pop();

                 // if all the elements have been removed from the array it means the request is complete
                if(stravaComplete.length == 0) {
                    // reinitialize map
                    initMap(stravaActivityList);
                }
             });
        }
    }

});

Any guidance would be great. Thanks.

It's not clear if you need coordinates of start points only, or for the whole activity and what accuracy is required.

Response to query https://www.strava.com/api/v3/athlete/activities includes a field map => summary_polyline from which you should be able to extract coordinates of the whole (although simplified) activity. You can also use this polyline to display it in google maps.

If you, however, need even better accuracy you need to retrieve every activity and use map => summary_polyline or map => polyline fields.

To get full data streams should be used

Use summary_polyline[0] and summary_polyline[-1] (Ruby) instead of rounded values. See this code from Slava for an example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM