我如何在 Mapbox Android 中获取路线的原始 Json 数据

How can i get raw Json data for a route in Mapbox Android

如何获得原始数据,如 link 在 android MapboxDocsLink

中所示

我想使用此数据在到达目的地之前的每个小时获取坐标点

对于 Android,参见 https://docs.mapbox.com/android/java/examples/show-directions-on-a-map

onResponse() 内部:https://github.com/mapbox/mapbox-android-demo/blob/master/MapboxAndroidDemo/src/main/java/com/mapbox/mapboxandroiddemo/examples/javaservices/DirectionsActivity.java#L156

这将打印出响应的 json:Log.d("DirectionsActivity", "response.body().toJson(); = " + response.body().toJson());

Android Studio logcat 有最大字符限制,这就是为什么整个路线 JSON 可能不在 logcat 中(就像我的 JSON 下面的片段)。 https://gist.github.com/kiirpi/7747423 是如何打印出完整的东西。在此要点中,将 sb 替换为 response.body().toJson()

2020-08-13 13:50:30.189 3157-3157/com.mapbox.mapboxandroiddemo.debug D/DirectionsActivity:"response.body().toJson(); ="{
   "code":"Ok",
   "waypoints":[
      {
         "name":"Calle Real de la Alhambra",
         "location":[
            -3.588224,
            37.175903
         ]
      },
      {
         "name":"Calle Ancha de Capuchinos",
         "location":[
            -3.601397,
            37.184341
         ]
      }
   ],
   "routes":[
      {
         "routeIndex":"0",
         "distance":4226.283,
         "duration":1420.659,
         "geometry":"}d`|eA~f_zEmEnTcAbEiRjt@pL`OrFoT`CuFl@AjABrAs@xCcGfIyNvHeLvHoHvDgBN`DOpB}DjGwIlNeEpJ{FpMyG|Om@dCTzAd@r@zAIbAo@rAuAjBwEdE}IpGgJhHiIlJaGdEoAbGz@il@d_BcAvE}@vE{Ebl@aH`t@sFjj@e@fCyBbU}@dT?jG?xCbB|Sd@xF]zKaD`OeO~ZcAvBmFpKqG|RgD_I]q@u@UmOq\qBwEqCcEgCoAwDiAyQi\uJkUmE_R{AaGiBgJkGaZsAaG]}@qC_IsAmD{EwMsAiIcAuRsAyKeAoMe@oLcAkWm@wNkAyOW{BmEaVcFwWwCoO_EsRqBgSsAqU{@oCm@cCm@_@m@I_NdCsB^gXhGy\tFcLpBkKpAqH|As@R}@LcARm@ZmE\qGh@cGp@sFzCqBxBiMhJ_EtGoChG}@lFyBbMiBbN}@nMqBfSUbEG`FOrIgCpTcB~F{@pAxGrIyBbN?nC}@pK]vN]zJm@vHmEfZqCpUMhGOxNTnBVr@bKvb@N`ONtYvCnUpHpi@j@zH?|IeEz\s@vFsArKe@|J_@xTe@zJ]rIaCfd@sApBiBhA{AzCe@hEOdCdA|TLrAt@xBWf@M\?t@?z@{ARcFr@aIp@_^dDkcA~IkBRqB\_Df@cAr@kLRkA?uJ}@ca@yByFRcL`@wb@aADrANjFvXpbAbGjPrFjOtIfUbL`WnS{QvNsLtT{QpWsU",
         "weight":1946.376,
         "weight_name":"routability",
         "legs":[
            {
               "distance":4226.283,
               "duration":1420.659,
               "summary":"Paseo de los Coches, Calle Carrera del Darro",
               "steps":[
                  {
                     "distance":124.957,
                     "duration":23.992,
                     "geometry":"}d`|eA~f_zEmEnTcAbEiRjt@",
                     "name":"Calle Real de la Alhambra",
                     "mode":"driving",
                     "maneuver":{
                        "location":[
                           -3.588224,
                           37.175903
                        ],
                        "bearing_before":0.0,
                        "bearing_after":290.0,
                        "instruction":"Head west on Calle Real de la Alhambra",
                        "type":"depart"
                     },
                     "driving_side":"right",
                     "weight":26.053,
                     "intersections":[
                        {
                           "location":[
                              -3.588224,
                              37.175903
                           ],
                           "bearings":[
                              290
                           ],
                           "entry":[
                              true
                           ],
                           "out":0
                        },
                        {
                           "location":[
                              -3.588665,
                              37.176041
                           ],
                           "bearings":[
                              1,
                              113,
                              294
                           ],
                           "entry":[
                              false,
                              false,
                              true
                           ],
                           "in":1,
                           "out":2
                        }
                     ]
                  },
                  {
                     "distance":33.0,
                     "duration":24.94,
                     "geometry":"y`a|eA~wazEpL`O",
                     "name":"",
                     "mode":"driving",
                     "maneuver":{
                        "location":[
                           -3.589519,
                           37.17635
                        ],
                        "bearing_before":294.0,
                        "bearing_after":223.0,
                        "instruction":"Turn left",
                        "type":"turn",
                        "modifier":"left"
                     },
                     "driving_side":"right",
                     "weight":30.534,
                     "intersections":[
                        {
                           "location":[
                              -3.589519,
                              37.17635
                           ],
                           "bearings":[
                              114,
                              223,
                              280
                           ],
                           "entry":[
                              false,
                              true,
                              true
                           ],
                           "in":0,
                           "out":1
                        }
                     ]
                  },
                  {
                     "distance":160.0,
                     "duration":86.02,
                     "geometry":"gs`|eA`hbzErFoT`CuFl@AjABrAs@xCcGfIyNvHeLvHoHvDgB",
                     "name":"",
                     "mode":"driving",
                     "maneuver":{
                        "location":[
                           -3.589777,
                           37.176132
                        ],
                        "bearing_before":223.0,
                        "bearing_after":113.0,
                        "instruction":"Turn left",
                        "type":"turn",
                        "modifier":"left"
                     },
                     "driving_side":"right",
                     "weight":91.422,
                     "intersections":[
                        {
                           "location":[
                              -3.589777,
                              37.176132
                           ],
                           "bearings":[
                              43,
                              113,
                              291
                           ],
                           "entry":[
                              false,
                              true,
                              true
                           ],
                           "in":0,
                           "out":1
                        },
                        {
                           "location":[
                              -3.589309,
                              37.175922
                           ],
                           "bearings":[
                              183,
                              312
                           ],
                           "classes":[
                              "tunnel"
                           ],
                           "entry":[
                              true,
                              false
                           ],
                           "in":1,
                           "out":0
                        },
                        {
                           "location":[
                              -3.589311,
                              37.175884
                           ],
                           "bearings":[
                              3,
                              136
                           ],
                           "entry":[
                              false,
                              true
                           ],
                           "in":0,
                           "out":1
                        }
                     ]
                  },
                  {
                     "distance":145.0,
                     "duration":61.0,
                     "geometry":"yx~{eAlw_zEN`DOpB}DjGwIlNeEpJ{FpMyG|Om@dCTzAd@r@",
                     "name":"Paseo del Generalife",
                     "mode":"driving",
                     "maneuver":{
                        "location":[
                           -3.588487,
                           37.175198
                        ],
                        "bearing_before":152.0,
                        "bearing_after":277.0,
                        "instruction":"Turn right onto Paseo del Generalife",
                        "type":"turn",
                        "modifier":"right"
                     },
                     "driving_side":"right",
                     "weight":71.8,
                     "intersections":[
                        {
                           "location":[
                              -3.588487,
                              37.175198
                           ],
                           "bearings":[
                              144,
                              184,
                              277,
                              332
                           ],
                           "entry":[
                              false,
                              false,
                              true,
                              false
                           ],
                           "in":3,
                           "out":2
                        }
                     ]
                  },
                  {
                     "distance":140.0,
                     "duration":68.25,
                     "geometry":"}_`|eArkbzEzAIbAo@rAuAjBwEdE}IpGgJhHiIlJaGdEoAbGz@",
                     "name":"Paseo del Generalife",
                     "mode":"driving",
                     "maneuver":{
                        "location":[
                           -3.589834,
                           37.175823
                        ],
                        "bearing_before":268.0,
                        "bearing_after":174.0,
                        "instruction":"Turn left to stay on Paseo del Generalife",
                        "type":"continue",
                        "modifier":"left"
                     },
                     "driving_side":"right",
                     "weight":73.85,
                     "intersections":[
                        {
                           "location":[
                              -3.589834,
                              37.175823
                           ],
                           "bearings":[
                              88,
                              174,
                              307
                           ],
                           "entry":[
                              false,
                              true,
                              false
                           ],
                           "in":0,
                           "out":1
                        },
                        {
                           "location":[
                              -3.589829,
                              37.175777
                           ],
                           "bearings":[
                              138,
                              231,
                              354
                           ],
                           "entry":[
                              true,
                              false,
                              false
                           ],
                           "in":2,
                           "out":0
                        }
                     ]
                  },
                  {
                     "distance":665.0,
                     "duration":317.373,
                     "geometry":"cc~{eAdw`zEil@d_BcAvE}@vE{Ebl@aH`t@sFjj@e@fCyBbU}@dT?jG?xCbB|Sd@xF]zKaD`OeO~ZcAvBmFpKqG|R",
                     "name":"Paseo de los Coches",
                     "mode":"driving",
                     "maneuver":{
                        "location":[
                           -3.588995,
                           37.17485
                        ],
                        "\"bearing_befor"