先看效果:
谷歌地图轨迹播放.gif在国内用到百度地图和高度地图都提供了比较好用的API接口, 用起来也顺手, 但是国外用到谷歌地图的时候, 就有点区别了. 要用到一个轨迹回放的功能, 找了半天,找父类, 父父类, 都发现谷歌没有提供相关API, 只提供了一个相关的类GMSMarkerLayer
, 但是并没有描述比较有用的信息:
然后再官网找更加具体的描述, 谷歌api参考 , 没啥有用的信息.
核心动画简单实现下, 可以参考:
NSMutableArray *latitudes = [NSMutableArray array];
NSMutableArray *longitudes = [NSMutableArray array];
//for循环我只是在搞坐标, 可以忽略模型
for (JJGPSModel *model in self.markers)
{
float x = model.location.coordinate.longitude;
float y = model.location.coordinate.latitude;
[longitudes addObject:[NSNumber numberWithFloat:x]];
[latitudes addObject:[NSNumber numberWithFloat:y]];
}
CAKeyframeAnimation *horizontalAnimation = [CAKeyframeAnimation animationWithKeyPath:@"longitude"];
horizontalAnimation.values = longitudes;
horizontalAnimation.duration = 3;
CAKeyframeAnimation *verticleAnimation = [CAKeyframeAnimation animationWithKeyPath:@"latitude"];
verticleAnimation.values = latitudes;
verticleAnimation.duration = 3;
CAAnimationGroup *group = [[CAAnimationGroup alloc] init];
group.animations = @[horizontalAnimation, verticleAnimation];
group.duration = 3;
group.repeatCount = 1;
[carMarker.layer addAnimation:group forKey:[NSString stringWithFormat:@"%@",carMarker.description]];
记录下, 以后方便使用.
网友评论