ios - 使用来自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
}
}
解决方案
推荐阅读
- c++ - 使经典的 Singleton 实现线程安全时面临的问题
- reactjs - TypeScript 的 React.Component 如何
泛型类型?
- node.js - webpack 版本导致的 npm start 错误
- react-native - 如何在不刷新的情况下在导航堆栈之间切换
- java - 注意:MainActivity 使用或覆盖已弃用的 API。注意:使用 -Xlint:deprecation 重新编译以获取详细信息
- vbscript - 从 classic.asp 以条带创建订阅的正确语法
- angular - Angular 中的 MathJax v3 - 在页面加载后渲染 TeX(在 ngOnInit 之后)
- java - java.lang.ExceptionInInitializerError。java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
- qt - 想要更改 QTableWidget 中选定单元格的字体大小
- php - 如何从 wp-includes 文件夹中获取versions.php文件作为对象?