在Google Map上移动注释,就像在Swift中使用Uber iOS应用程序一样?

时间:2017-05-04 06:34:22

标签: ios iphone google-maps swift3 xcode8

我正在尝试开发基于Uber和Ola概念的应用程序。所以对于这个我需要整合谷歌地图的接送地点离子iOS。那么请告诉我如何使用Google地图在iOS中实现移动注释(汽车)动画。

1 个答案:

答案 0 :(得分:4)

使用Swift 3.1

Error:(29, 47) missing parameter type for expanded function ((x$1: <error>, x$2) => x$1.$plus(x$2))
Functor.listFunctor.map(List(1,2,3,4))(_ + _)
                                       ^
        var oldCoodinate: CLLocationCoordinate2D? = CLLocationCoordinate2DMake(CDouble((data.value(forKey: "lat") as? CLLocationCoordinate2D)), CDouble((data.value(forKey: "lng") as? CLLocationCoordinate2D)))
        var newCoodinate: CLLocationCoordinate2D? = CLLocationCoordinate2DMake(CDouble((data.value(forKey: "lat") as? CLLocationCoordinate2D)), CDouble((data.value(forKey: "lng") as? CLLocationCoordinate2D)))
        driverMarker.groundAnchor = CGPoint(x: CGFloat(0.5), y: CGFloat(0.5))
        driverMarker.rotation = getHeadingForDirection(fromCoordinate: oldCoodinate, toCoordinate: newCoodinate)
        //found bearing value by calculation when marker add
        driverMarker.position = oldCoodinate
        //this can be old position to make car movement to new position
        driverMarker.map = mapView_
        //marker movement animation
        CATransaction.begin()
        CATransaction.setValue(Int(2.0), forKey: kCATransactionAnimationDuration)
        CATransaction.setCompletionBlock({() -> Void in
            driverMarker.groundAnchor = CGPoint(x: CGFloat(0.5), y: CGFloat(0.5))
            driverMarker.rotation = CDouble(data.value(forKey: "bearing"))
            //New bearing value from backend after car movement is done
        })
        driverMarker.position = newCoodinate
        //this can be new position after car moved from old position to new position with animation
        driverMarker.map = mapView_
        driverMarker.groundAnchor = CGPoint(x: CGFloat(0.5), y: CGFloat(0.5))
        driverMarker.rotation = getHeadingForDirection(fromCoordinate: oldCoodinate, toCoordinate: newCoodinate)
        //found bearing value by calculation
        CATransaction.commit()

从旧坐标和新坐标获取方位值的方法

extension Int {
    var degreesToRadians: Double { return Double(self) * .pi / 180 }
}
extension FloatingPoint {
    var degreesToRadians: Self { return self * .pi / 180 }
    var radiansToDegrees: Self { return self * 180 / .pi }
}
目标C代码

Move GMSMarker on Google Map Like UBER

对于github:ARCarMovement