5

I am making an app in Android with some function same to Google Map find direction to specific location.

I had draw route(polyline) from one place to another place received by google direction API. Here my question is that I want to put current traffic data on that particular poly line only.

If we are finding direction from web than we are not getting any traffic data but if we are finding it from Google Map App from mobile then we can see it.

Does anyone know how any solution? Please give me a clue!

1 Answers1

2

There is no reasonably easy and convenient way to get the Google Maps traffic data along particular poly line only. But, if you get Directions API JSON response then you can parse "legs" and "steps" tags:

 ... 
 "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
                 },
  ...

and get "distance" and "duration" values from them. Then you can calculate speed = distance / duration and interpret leg/step speed as traffic indicator.

Also take a look at this question of Tejaswi Yerukalapudi and answers.

Also check Google Maps Platform Terms of Service.

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79