如何平滑移动GMSMarker沿着目标c中的坐标 [英] How to smoothly move GMSMarker along coordinates in Objective c

查看:107
本文介绍了如何平滑移动GMSMarker沿着目标c中的坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用google map sdk。我想每5秒更新一次pin的gps坐标。目前我只是更新GMSMarker的位置属性。但它会产生跳跃效应。我想在地图上平滑地移动标记。

这里是我的代码来更新标记的位置

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


解决方案

更多类似这样的内容:

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

我们使您可以使用核心动画,用于动画Google地图。

对于一个工作示例,请参阅SDK示例应用程序中的 AnimatedCurrentLocationViewController。{c,m} p>

I'm using google map sdk. I want to update gps coordinates of pin after each 5 seconds. Currently I'm just updating position attribute of GMSMarker. But it gives jump effect. I want to move marker smoothly on map.
Here is my code to update position of marker

-(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; 
}

解决方案

Change your else block to be something more like this:

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

We enable you to use Core Animation for animating Google Maps.

For a worked sample, please see AnimatedCurrentLocationViewController.{c,m} in the SDK sample application.

这篇关于如何平滑移动GMSMarker沿着目标c中的坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆