How to calculate the estimated time of arrival between two points - Swift/Google Maps

Viewed 3034

I was wondering if there was a way to calculate the estimated time of arrival between two points the user chooses using Google Maps. I have read through on Stack Overflow, however most of the ones that I have seen talking about estimated time of arrival, refer to the Google Maps documentation which I find rather confusing. I would appreciate it if someone could give me an explanation along with their code so I can see how to replicate the same thing myself.

Below shows an example of what I want.(I want the time of arrival which in this case is 1 hour and 17 minutes)

Example

1 Answers

You will get duration in traffic tag in json. Something like below. You can calculate the time of arrival depending on your duration. Please also note that 'duration' gives travel time without considering traffic. 'duration_in_traffic' is the one you have to use.

"legs" : [
        {
           "distance" : {
              "text" : "12.9 km",
              "value" : 12910
           },
           "duration" : {
              "text" : "27 mins",
              "value" : 1615
           },
           "duration_in_traffic" : {
              "text" : "29 mins",
              "value" : 1747
           }]

Here is the sample for Google Maps

https://www.appcoda.com/google-maps-api-tutorial

Related