MKMapview 实时汽车跟踪

MKMapview live car tracking

我的要求是创建一个显示出租车实时跟踪的应用程序。喜欢Ola,uber等著名的汽车应用程序。

请告诉我如何更新注释,即使是街道转弯和汽车倒车。如何使用 MKMapview 模拟移动注释。我必须使用的任何图书馆。我搜索过,但找不到任何图书馆

这个问题的解决方案非常简单。如果你在实现这个库时遇到问题,为什么不自己做并学习一些东西呢?您只需创建某种类型的 Vehicle 模型 class 来存储坐标和先前的坐标。为了能够在地图上显示它,它必须遵守 MKAnnotation 协议 - 实现:标题、副标题和坐标。 newCoordinate 位置将在从网络获取位置数据时默认设置。您需要跟踪两个值才能成功制作动画。

然后实现这样的东西:

@interface Vehicle : NSObject <MKAnnotation>

@property (nonatomic, readonly, copy) NSString *title;
@property (nonatomic, readonly, copy) NSString *subtitle;

@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, assign) CLLocationCoordinate2D newCoordinate;

@end

设置新坐标后,您将先前的值从自定义 setter 移动到坐标 属性 中。执行此操作后,您只需像往常一样为注释设置动画。

// new coordinate obtained from networking
- (void)setNewCoordinate:(CLLocationCoordinate2D)newCoordinate {

    // implement the value moving part

    _newCoordinate = newCoordinate;
}

但是在检测动画注释上的点击时要小心,因为它的工作方式。当动画开始到完成帧的值时,将设置注释帧。您需要在动画期间显示在屏幕上的注释的 presentationLayer 上点击测试。

处理点击覆盖

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
}

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
}

动画

[UIView animateWithDuration:0 
                      delay:0 
                    options:UIViewAnimationOptionCurveEaseIn 
                 animations:^{

} completion:nil];

很抱歉,我不能在这里 post 编写代码,因为我之前已经为我的雇主实施了此代码并且受合同约束。

因为我认为问题是地图上的注释平滑转动。因为您可以放置​​自己的自定义图像而不是默认的蓝点。

为了平滑转动,您可以使用 CMMotionManager,因为它可以为您提供加速度,因此您可以通过引用注释视图来旋转图像。您可以使用更新设备运动数据更新加速度数据。当您沿 x、y 和 z 获得 useracceleration 时,您可以通过 tan function.This 获得角度应该可以解决您的问题

获取角度的代码

[motionManager startDeviceMotionUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMDeviceMotion *motion, NSError *error) {
    double angle = atan(motion.userAcceleration.x/motion.userAcceleration.y);
}];