Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在google map ios中将带有动画的标记从一个位置平滑地移动到另一个位置_Ios_Google Maps - Fatal编程技术网

如何在google map ios中将带有动画的标记从一个位置平滑地移动到另一个位置

如何在google map ios中将带有动画的标记从一个位置平滑地移动到另一个位置,ios,google-maps,Ios,Google Maps,基于纬度和经度创建的标记(如下图所示)帮助我通过动画将标记移动到另一个位置 GMSMarker *marker1 = [[GMSMarker alloc] init]; marker1.position = CLLocationCoordinate2DMake(12.9716, 77.5946); marker1.title = @"Bangalore"; marker1.groundAnchor = CGPointMake(0.2, 0.9); marker1.appearAnimation

基于纬度和经度创建的标记(如下图所示)帮助我通过动画将标记移动到另一个位置

GMSMarker *marker1 = [[GMSMarker alloc] init];
marker1.position = CLLocationCoordinate2DMake(12.9716, 77.5946);
marker1.title = @"Bangalore";
marker1.groundAnchor = CGPointMake(0.2, 0.9);
marker1.appearAnimation = kGMSMarkerAnimationPop;
marker1.icon = [UIImage imageNamed:@"Flag Filled -50.png"];
marker1.snippet = @"India";
marker1.map = _mapView;

您可以使用GMSMarker的setRotation方法。希望它能起作用。

使用Xcode 9 Swift 4:平滑移动标记。

@objc func moveMarker(){
    self.lat += 0.0017
    CATransaction.begin()
    CATransaction.setValue(2.0, forKey: kCATransactionAnimationDuration)
    CATransaction.setCompletionBlock {
        self.marker.groundAnchor = CGPoint(x: 0.5, y: 0.5)
    }
    self.mapView.animate(to: GMSCameraPosition.camera(withLatitude: self.lat, longitude: self.lon, zoom: 15))
    self.marker.position = CLLocationCoordinate2D(latitude: self.lat, longitude: self.lon)
    CATransaction.commit()
    self.marker.map = self.mapView
}
您的标记将在地图上移动,就像优步的汽车在地图上移动一样

没有必要提及
.groundAnchor
属性,请阅读谷歌文档

另外,在传递
CATransaction
中的值之前,更新
self.lat
self.lon
。(
lat
lon
是具有默认值的全局变量)

最后,我使用了
Timer.scheduledTimer
调用

    override func viewDidAppear(_ animated: Bool) {
       var timer = Timer()
       timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(moveMarker), userInfo: nil, repeats: true)
    }
我打赌它会帮助一些人

结果:


设置旋转使标记旋转一定程度。但我需要将标记从一个花边移动到另一个花边。感谢帮助。请查看设置位置,然后再次传递lat long和fitMap。这会更改标记位置,但我需要根据lat long值将标记从旧位置动画化为新位置。可能重复-您可以添加标记旋转和方位取决于你的后端是如何发送坐标,方位角等。我认为你的动画间隔应该小于定时器间隔。。。。