首页 > 解决方案 > 使用来自iOS中步骤点折线的谷歌方向api在GMS折线中平滑动画

问题描述

我正在尝试使用 google direction api 移动平滑的动画折线。从 API 响应中,我从腿数组的步骤中获取每个折线点。正如下面的书面代码,动画折线的输出不会像我想要的那样连续移动,因此请给出任何关于折线在绘制路线上的规则或连续移动的想法。

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
    }

}

标签: iosswift

解决方案


推荐阅读