Guest User

Untitled

a guest
Jul 20th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. var gmsPath = GMSMutablePath()
  2. var path = GMSPath()
  3. var polyline = GMSPolyline()
  4. var animationPath = GMSMutablePath()
  5. var animationPolyline = GMSPolyline()
  6.  
  7. func polyline(){
  8.  
  9. self.createPolyline(arrStep: arrPath, complitionBlock: { (success) in
  10. if success{
  11. print("Success")
  12. self.timer = Timer.scheduledTimer(timeInterval: 0.3, target: self, selector: #selector(self.animatePath), userInfo: nil, repeats: true)
  13. }else{
  14. print("Did not success")
  15. }
  16. })
  17. }
  18.  
  19. ////Create Polyline On MAP
  20.  
  21. func createPolyline(arrStep:[String],complitionBlock : @escaping (Bool)->Void){
  22.  
  23. for points in arrStep{
  24.  
  25. self.gmsPath.appendPath(path: GMSMutablePath(fromEncodedPath: points))
  26. self.polyline.path = gmsPath
  27. self.polyline.strokeColor = UIColor.blue
  28. self.polyline.strokeWidth = 4.0
  29. self.polyline.map = self.gmsMapView
  30. }
  31. complitionBlock(true)
  32. }
  33. ////Animate Path In Polyline
  34.  
  35. @objc func animatePath() {
  36.  
  37. if (self.i < self.gmsPath.count()){
  38. self.animationPath.add(self.gmsPath.coordinate(at: UInt(self.i)))
  39. self.animationPolyline.path = self.animationPath
  40. self.animationPolyline.strokeColor = UIColor.purple
  41. self.animationPolyline.strokeWidth = 4
  42. self.animationPolyline.map = self.gmsMapView
  43. self.i += 1
  44. }else{
  45. self.i = 0
  46. self.animationPath = GMSMutablePath()
  47. self.animationPolyline.map = nil
  48. }
  49.  
  50. }
Add Comment
Please, Sign In to add comment