{"id":1023,"date":"2021-03-14T11:24:19","date_gmt":"2021-03-14T09:24:19","guid":{"rendered":"http:\/\/www.joanillo.org\/?p=1023"},"modified":"2021-03-14T11:29:55","modified_gmt":"2021-03-14T09:29:55","slug":"segmentos-de-ciclismo-con-la-api-de-strava","status":"publish","type":"post","link":"https:\/\/www.joanillo.org\/?p=1023&lang=es","title":{"rendered":"Segmentos de ciclismo con la API de Strava"},"content":{"rendered":"<p><a href=\"http:\/\/www.joanillo.org\/wp-content\/uploads\/2021\/03\/strava_api.png\"><img src=\"http:\/\/www.joanillo.org\/wp-content\/uploads\/2021\/03\/strava_api.png\" alt=\"\" title=\"Strava API\" width=\"276\" class=\"alignright size-medium wp-image-2338\"><\/a>De la API de Strava me interesa sobretodo la parte de <em>segmentos<\/em>, que son trozos de rutas donde la gent se cronometra y se publican los rankings. Sin una subscripci\u00f3n Premium no se puede acceder a toda la informaci\u00f3n. Jugando un rato con la API de Strava he llegado a poder ver los segmentos que hay en una zona geogr\u00e1fica, y poder ver los puntos de este segmento, que se pueden representar en cualquier mapa.<\/p>\n<p>Para acceder a la informaci\u00f3n de un segmento:<\/p>\n<pre>$ curl -X GET https:\/\/www.strava.com\/api\/v3\/segments\/229781 -H 'Authorization: Bearer *******************'\n<\/pre>\n<p>Y el resultado:<\/p>\n<pre>{\"id\":229781,\"resource_state\":3,\"name\":\"Hawk Hill\",\"activity_type\":\"Ride\",\"distance\":2684.82,\"average_grade\":5.8,\"maximum_grade\":10.9,\"elevation_high\":247.2,\"elevation_low\":92.0,\"start_latlng\":[37.833112,-122.483436],\"end_latlng\":[37.828072,-122.498139],\"elevation_profile\":\"https:\/\/d3o5xota0a1fcr.cloudfront.net\/v6\/charts\/KO5P7GCFLK5P5NF5GNUX3D6IVFLIEYRYD6JRBEGMXHOCPENJUQZXD5IIEJOYINQE2HX3XLZMYRTF5GHG5JLQ====\",\"start_latitude\":37.833112,\"start_longitude\":-122.483436,\"end_latitude\":37.828072,\"end_longitude\":-122.498139,\"climb_category\":1,\"city\":\"San Francisco\",\"state\":\"CA\",\"country\":\"United States\",\"private\":false,\"hazardous\":false,\"starred\":false,\"created_at\":\"2009-09-21T20:29:41Z\",\"updated_at\":\"2021-03-13T09:01:33Z\",\"total_elevation_gain\":155.2,\n\n\"map\":{\"id\":\"s229781\",\"polyline\":\"}g|eFnpqjVl@En@Md@HbAd@d@^h@Xx@VbARjBDh@OPQf@w@d@k@XKXDFPF\\\\CbGT`AV`@v@|@NTNb@?XOb@cAxAWLuE@eAFMBoAv@eBt@q@b@}@tAeAt@i@dAC`AFZj@dBA~@Yh@MbAVn@b@b@\\\\d@Ef@Qd@_@d@eB|@c@h@YfBI|AMpA?VF\\\\\\\\t@f@t@h@j@|@b@hCb@b@XTd@Bl@GtA?jAL`ALp@Tr@RXd@Rx@Pn@^Zh@Tx@Zf@`@FTCzDy@f@Yx@m@n@Op@VJr@\",\"resource_state\":3},\n\n\"effort_count\":556805,\"athlete_count\":49100,\"star_count\":5022,\"athlete_segment_stats\":{\"pr_elapsed_time\":null,\"pr_date\":null,\"pr_activity_id\":null,\"effort_count\":0},\"xoms\":{\"kom\":\"5:37\",\"qom\":\"6:42\",\"destination\":{\"href\":\"strava:\/\/segments\/229781\/leaderboard\",\"type\":\"overall\",\"name\":\"All-Time\"}},\"local_legend\":{\"athlete_id\":54312907,\"title\":\"Dalton Nonweiler\",\"profile\":\"https:\/\/dgalywyr863hv.cloudfront.net\/pictures\/athletes\/54312907\/14907176\/5\/large.jpg\",\"effort_description\":\"86 efforts in the last 90 days\",\"effort_count\":\"86\",\"effort_counts\":{\"overall\":\"86 efforts\",\"female\":\"41 efforts\"},\"destination\":\"strava:\/\/segments\/229781\/local_legend?categories%5B%5D=overall\"}}\n<\/pre>\n<p>Vemos que la <em>polilinea<\/em> est\u00e1 codificada en una cadena de texto. La podemos decodificar y obtener las coordenadas:<\/p>\n<pre>$ pip3 install polyline\n\n$ python3\n&gt;&gt; import polyline\n&gt;&gt; #polyline.decode(summary_polyline)\n&gt;&gt; polyline.decode(\"gxu{Fem|Kc@fAq@fAoApAMR[ZMXw@v@a@VQZi@j@sAhAk@hA_@f@oDxCiAhA_@j@a@~@{@pCC`@EFD^H`B?`@BNNZV@JGDMEqA@q@H]NOFSLo@t@eB^i@d@i@t@m@n@Yz@EHBR\\\\`AdDFdEJ`@RNHIVGf@ATH`At@VXDl@GJU@WY[e@YSKC_@GgA@YMKMc@eBYeBSWg@AUTSVa@|@[tAAPDb@Nr@@TCb@[bACd@BNJ^Xh@N^BNB`@Nn@DJTNZ\\\\Rn@?\\\\c@zAA^B\\\\JZHHh@NZDVHTRHJBNAb@I|@B\\\\Th@PTVf@F`@Cl@Sj@WJ{Ae@{@OKBSPOr@IvA[z@UTw@JWE_@]QUUKKCu@Hs@NMEIIi@kAOUGE]OUMGIGY?y@XiB@]E]U[SGU?c@XcA`Aw@|@i@~@WbASPK?IC_Au@q@_@SAI@g@Lo@XK?YB[MYOQSQYi@Y_@AK@CDg@X]Bg@KUMi@e@[k@GU@MHQb@a@DIFU@WIYg@u@]y@IqAP{ABq@Is@e@iB}@wAw@oBk@aAa@g@g@w@Km@Q{AYkB_AmCc@eB?]H]NWxAiBZq@JYFm@@m@C[G]OWa@k@eAu@o@k@iBkCm@k@SKc@CK@]LS@e@]]]E@GDEH@`@PZJd@CHEFI?OSMe@Uk@\")\n\n[(41.40436, 2.11683), (41.40454, 2.11647), (41.40479, 2.11611), (41.40519, 2.1157), (41.40526, 2.1156), (41.4054, 2.11546), (41.40547, 2.11533), \n...\n(41.41868, 2.11667), (41.41859, 2.11653), (41.41853, 2.11634), (41.41855, 2.11629), (41.41858, 2.11625), (41.41863, 2.11625), (41.41871, 2.11635), (41.41878, 2.11654), (41.41889, 2.11676)]\n<\/pre>\n<p>Refer\u00e8ncies:<\/p>\n<ul>\n<li><a href=\"http:\/\/wiki.joanillo.org\/index.php\/API_de_Strava\">http:\/\/wiki.joanillo.org\/index.php\/API_de_Strava<\/a><\/li>\n<li><a href=\"https:\/\/developers.strava.com\/\">https:\/\/developers.strava.com\/<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>De la API de Strava me interesa sobretodo la parte de segmentos, que son trozos de rutas donde la gent se cronometra y se publican los rankings. Sin una subscripci\u00f3n Premium no se puede acceder a toda la informaci\u00f3n. Jugando un rato con la API de Strava he llegado a poder ver los segmentos que [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[300,324,340,192,346],"tags":[],"_links":{"self":[{"href":"https:\/\/www.joanillo.org\/index.php?rest_route=\/wp\/v2\/posts\/1023"}],"collection":[{"href":"https:\/\/www.joanillo.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.joanillo.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.joanillo.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.joanillo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1023"}],"version-history":[{"count":2,"href":"https:\/\/www.joanillo.org\/index.php?rest_route=\/wp\/v2\/posts\/1023\/revisions"}],"predecessor-version":[{"id":1028,"href":"https:\/\/www.joanillo.org\/index.php?rest_route=\/wp\/v2\/posts\/1023\/revisions\/1028"}],"wp:attachment":[{"href":"https:\/\/www.joanillo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.joanillo.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.joanillo.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}