I am trying to move smoothly animated polyline with using google direction api. From API Response, I am getting each polyline points from steps of legs Array. As Written code below , output of animation polyline is not moving continously as I want, So give any idea for regular or continuous movement of poly line on drawn route.
var gmsPath = GMSMutablePath()
var path = GMSPath()
var polyline = GMSPolyline()
var animationPath = GMSMutablePath()
var animationPolyline = GMSPolyline()
func polyline(){
self.createPolyline(arrStep: arrPath, complitionBlock: { (success) in
if success{
print("Success")
self.timer = Timer.scheduledTimer(timeInterval: 0.3, target: self, selector: #selector(self.animatePath), userInfo: nil, repeats: true)
}else{
print("Did not success")
}
})
}
////Create Polyline On MAP
func createPolyline(arrStep:[String],complitionBlock : @escaping (Bool)->Void){
for points in arrStep{
self.gmsPath.appendPath(path: GMSMutablePath(fromEncodedPath: points))
self.polyline.path = gmsPath
self.polyline.strokeColor = UIColor.blue
self.polyline.strokeWidth = 4.0
self.polyline.map = self.gmsMapView
}
complitionBlock(true)
}
////Animate Path In Polyline
@objc func animatePath() {
if (self.i < self.gmsPath.count()){
self.animationPath.add(self.gmsPath.coordinate(at: UInt(self.i)))
self.animationPolyline.path = self.animationPath
self.animationPolyline.strokeColor = UIColor.purple
self.animationPolyline.strokeWidth = 4
self.animationPolyline.map = self.gmsMapView
self.i += 1
}else{
self.i = 0
self.animationPath = GMSMutablePath()
self.animationPolyline.map = nil
}
}