ios - 如何制作自定义图钉并同时使用 FollowWithHeading 模式?

标签 ios gps annotations mapkit mkusertrackingmode

下面的代码是显示自定义引脚(图片为引脚)。可以正常使用。

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {

   PVAttractionAnnotationView *annotationView = [[PVAttractionAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Attraction"];
   annotationView.canShowCallout = YES;
   return annotationView;

}

然后使用下面的代码显示当前位置

[self.mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading];

XCODE跳转到main.m并显示

Thread 1:Signal SIGABRT

另一方面,如果我使用下面的代码

[self.mapView setUserTrackingMode:MKUserTrackingModeFollowWithHeading];

并且未使用以下所有代码

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {

   PVAttractionAnnotationView *annotationView = [[PVAttractionAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Attraction"];
   annotationView.canShowCallout = YES;
   return annotationView;

}

应用程序 将正常显示当前位置,但不会显示自定义 pin。它显示的是系统默认的红色引脚,因为我没有使用该代码。

如何制作自定义图钉并同时使用 FollowWithHeading 模式?

..抱歉我英语不好。

最佳答案

您需要对检查注释类并返回适当 View 的 viewForAnnotation 稍作更改。通过返回 nil,系统将使用默认 View 。您还需要一些额外的代码来正确实现 View 重用 -

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    MKAnnotationView *annotationView=nil;
    if ([annotation isKindOfClass:[PVAttractionAnnotation class]])  // Note - put your custom annotation class here
    {
        annotationView =(MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"Attraction"];
        if (annotationView == nil)
        {
            annotationView = [[PVAttractionAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Attraction"];  
            annotationView.canShowCallout = YES; 
        }
        else
        {
            annotationView.annotation=annotation;
        }

    }
    return annotationView;
}

关于ios - 如何制作自定义图钉并同时使用 FollowWithHeading 模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22947722/

相关文章:

java - 基于注解的工厂方法

javascript - 有没有办法使用 Javascript/HTML5 从 USB 设备获取 GPS 位置?

android - 如何解决 GPS 在后台 android Pie 中自动关闭?

ios - 将 Xcode 调试器附加到在 iOS 模拟器中运行的 Xamarin 应用程序

ios - UIView.animateWithDuration 的交互式过渡完成 block 从未在 animateTransition 内部调用

android - 如何从 Android 中的 GPS 获取坐标?

java - 为什么CDI使用注释参数时不满足依赖关系?

java - 如何定义一个自动获取重写方法的java注释?

iOS 联系人搜索应用

objective-c - 更改 UITextField 键盘的色调