【问题标题】:How to smoothly move GMSMarker along coordinates in Objective c如何沿着Objective c中的坐标平滑移动GMSMarker
【发布时间】:2013-10-01 11:44:00
【问题描述】:

我正在使用谷歌地图 SDK。我想每 5 秒更新一次 pin 的 gps 坐标。目前我只是在更新 GMSMarker 的位置属性。但它给出了跳跃效果。我想在地图上顺利移动标记。
这是我更新标记位置的代码

-(void)updateLocationoordinates(CLLocationCoordinate2D) coordinates
{ 
  if (marker == nil) {
      marker = [GMSMarker markerWithPosition:coordinates];
      marker.icon = [UIImage imageNamed:CAR_FOUND_IMAGE];
      marker.map = mapView_;
  } else
  marker.position = coordinates; 
}

【问题讨论】:

    标签: objective-c google-maps


    【解决方案1】:

    将 else 块更改为更像这样的内容:

    [CATransaction begin];
    [CATransaction setAnimationDuration:2.0];
    marker.position = coordindates;
    [CATransaction commit];
    

    我们允许您使用 Core Animation 为 Google 地图制作动画。

    有关工作示例,请参阅 SDK 示例应用程序中的 AnimatedCurrentLocationViewController.{c,m}

    【讨论】:

    • 谢谢@Brett。我更新了 google sdk,然后这些动画效果很好。
    • 对我来说,这实际上没有用。事实上,它完全破坏了 .position 属性的动画。好消息是正是我想要的:一种关闭 .position 属性动画的方法。万分感谢!作为参考,我将动画持续时间设置为 0.0,但具有非 0 值仍然没有动画。
    • 好吧——我撒谎了。它的工作原理与海报提到的完全一样。我刚刚搞砸了我的测试。然而,我注意到编辑我的第一条评论为时已晚。
    • 任何人都可以发送代码 sn-p 来动画谷歌地图的折线。
    • @Sadia 你能告诉我你是怎么做到的吗?
    【解决方案2】:

    布雷特在 swift -3 和 4 中的回答

    CATransaction.begin()
    CATransaction.setAnimationDuration(2.0)
    marker.position = coordindates
    CATransaction.commit()
    

    【讨论】:

      【解决方案3】:

      只需在视图中初始化标记并在您想要这样做时加载并更新它,不需要任何类型的动画,例如

      - (void)viewDidLoad {
          [super viewDidLoad];
          ..write code here
              marker = [[GMSMarker alloc] init];
      }
          marker.position = CLLocationCoordinate2DMake([latitudue doubleValue], [longitude doubleValue]);
      

      【讨论】:

        猜你喜欢
        • 2016-05-25
        • 2016-10-14
        • 1970-01-01
        • 1970-01-01
        • 2017-07-30
        • 1970-01-01
        • 1970-01-01
        • 2020-05-04
        • 1970-01-01
        相关资源
        最近更新 更多