【问题标题】:How to plot current traffic data to google map on specific poly line that have been drawn by Google Direction API如何将当前交通数据绘制到谷歌地图上由谷歌方向 API 绘制的特定折线上
【发布时间】:2018-11-28 12:23:53
【问题描述】:

我正在 Android 中制作一个应用程序,其功能与 Google Map 查找特定位置的方向相同。

我已经绘制了从一个地方到另一个地方的路线(折线),由谷歌方向 API 接收。我的问题是我只想将当前的交通数据放在特定的折线上。

如果我们从网络上查找方向,则我们不会获得任何交通数据,但如果我们是从移动设备上的 Google 地图应用程序中找到它,那么我们可以看到它。

有谁知道如何解决?请给我一个线索!

【问题讨论】:

    标签: android google-maps kotlin google-directions-api


    【解决方案1】:

    没有相当简单和方便的方法来获取仅沿特定折线的 Google 地图交通数据。但是,如果您获得 Directions API JSON response,那么您可以解析 "legs""steps" 标签:

     ... 
     "legs" : [
            {
               "distance" : {
                  "text" : "35.9 mi",
                  "value" : 57824
               },
               "duration" : {
                  "text" : "51 mins",
                  "value" : 3062
               },
      ...
           "steps" : [
                  {
                     "distance" : {
                        "text" : "67 m",
                        "value" : 67
                     },
                     "duration" : {
                        "text" : "1 min",
                        "value" : 8
                     },
      ...
    

    并从中获取 "distance""duration" 值。然后您可以计算speed = distance / duration 并将腿/步speed 解释为流量指标。

    另请查看thisTejaswi Yerukalapudi 的问题和答案。

    同时检查Google Maps Platform Terms of Service

    【讨论】:

      猜你喜欢
      • 2013-07-02
      • 2023-04-06
      • 1970-01-01
      • 2011-12-03
      • 2016-05-14
      • 2015-10-17
      • 1970-01-01
      • 2019-05-11
      • 2013-05-30
      相关资源
      最近更新 更多