iosgoogle-mapsswift4.1

Swift 4 : How to redraw route if user change the direction in Google map ios


I'm working on an iOS App which draws the path on a map using Polyline options, between source to destination.

This works fine.

What I need is, if the user starts from source, and instead of taking drawn route towards the destination, the user takes another route, the path on the map should be redrawn for user's current path.

I'm using Directions API for drawing the path.

How can I do that?

Thanks in advance.


Solution

  • Yes, you can do that by detecting the change in location. Use didUpdateLocations method of CLLocationManagerDelegate Protocol to detect the change of location. If user location is changed significant then check that if user is still on route or not by using GMSGeometryContainsLocation function.