Determine distance on travelled path mkmapview swift

241 Views Asked by At

I have a functionality where user travels by his car from start to end location. I need to calculate the distance between the start and end locations on which the user has travelled. There may be multiple routes to the destination and I am getting these routes from MKDirectionRequest object. But how can I calculate the visited route by driver and its distance whether it may be the shortest or longest route.

1

There are 1 best solutions below

4
On

When driver location is getting updated then you need to store(on server may be) current location of the driver as he moves with car.

Once driver finishes ride then you need to calculate the distance from latitude & longitude.

so for that you need to add 2 buttons.

  1. Start Ride: So when user start the ride, user press start ride button and then you need to start listing the location updates as driver move with the car and store it on the server.

  2. Stop Ride: So as driver reaches to the destination then user presses the stop ride so here yo need to stop to listen the location updates and calculate the all stored lat. and long.

Hope it may help you.