I have successfully drawn a polyline from point a to point b, but for some reason , it shows linear line not the correct waypoints
Here's the code
let path = GMSMutablePath()
path.addLatitude(3.1970044, longitude:101.7389365)
path.addLatitude(3.2058354, longitude:101.729536)
let polyline = GMSPolyline(path: path)
polyline.strokeWidth = 5.0
polyline.geodesic = true
polyline.map = mapView
I was expecting that it would be doing some waypoints, but it just shows straight polylines
self.googleMapsView is the google maps view.
Example : self.getDirections("26.9211992,75.8185761", destination: "26.8472496,75.7691909", waypoints: ["26.8686811,75.7568383"], travelMode: nil, completionHandler: nil)
Example: google direction link https://maps.googleapis.com/maps/api/directions/json?origin=26.9211992,75.8185761&destination=26.8472496,75.7691909&waypoints=optimize:true|26.8686811,75.7568383
For swift 5
You need to get all the points for the route. To get the route you need to use Google Direction API https://developers.google.com/maps/documentation/directions/. Then use the 1st result of array that will be the shortest one, use the encoded path to draw a poly line using pathFromEncodedPath: method.
A small improvement to Azharhussain Shaikh's answer.
To call the function :
What I have changed: 1. Parameter passing 2. Position was given statically. I changed it.
For Swift 3.0 Please use this code...