thedansaps
thedansaps

Reputation: 611

Swift: Get travel time between two location using Google Maps

I have an app that uses Google Maps and I want to get the travel time between my current location and another location. How will I do that? Thanks in advance.

Upvotes: 2

Views: 4813

Answers (1)

PK20
PK20

Reputation: 1066

You can use CLLocation to calculate the distance between two locations. Something like,

CLLocationDistance meters = [newLocation distanceFromLocation:oldLocation];

Once you calculated the distance, then you can easily calculate the travel time by using the speed distance time formula

i.e., speed = distance / time

since you know the distance and if you assume the speed, you can calculate time taken for the travel as

time = distance / speed

Checkout this link to use Google Maps API to calculate the time travel.

Upvotes: 3

Related Questions