具有自定义注释、标注和蓝色精度圆圈的当前位置

发布于 2024-09-06 02:50:06 字数 1109 浏览 0 评论 0原文

经过两个小时的谷歌搜索后,我找不到答案,所以这是我的最后一次尝试。

我想在 mkmapview 上为用户当前位置使用自定义注释。但我也想在它周围有蓝色的精度圆圈。

这可以做到吗?

如果没有,我可以向默认的带圆圈的蓝点添加标注吗?

我需要这个的原因是因为在我的应用程序上,当前位置点经常在其他注释下消失。这就是为什么我使用带有标注的紫色图钉作为当前位置。

这是我的注释代码:

if ([annotation isKindOfClass:MKUserLocation.class]) 
    {
        MKPinAnnotationView *userAnnotationView = (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:@"UserLocation"];
        if (userAnnotationView == nil)  {
            userAnnotationView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"UserLocation"]autorelease];
        }            
        else 
            userAnnotationView.annotation = annotation;

        userAnnotationView.enabled = YES;
        userAnnotationView.animatesDrop = NO;
        userAnnotationView.pinColor = MKPinAnnotationColorPurple;
        userAnnotationView.canShowCallout = YES;
        [self performSelector:@selector(openCallout:) withObject:annotation afterDelay:0.01];

        return userAnnotationView;  
    }

感谢您的任何建议。干杯,克里斯蒂安

After 2 hours of googling I couldn't find an answer so this is my last shot.

I would like to use a custom annotation for the user current location on a mkmapview. But I also want to have the blue accuracy circle around it.

Can this be done?

If not, can I add a call-out to the default blue dot with circle?

The reason that I need this is because on my app, the current location dot often disappears under other annotations. So that's why I use a purple pin with a call-out as current location.

Here is my code for the annotation:

if ([annotation isKindOfClass:MKUserLocation.class]) 
    {
        MKPinAnnotationView *userAnnotationView = (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:@"UserLocation"];
        if (userAnnotationView == nil)  {
            userAnnotationView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"UserLocation"]autorelease];
        }            
        else 
            userAnnotationView.annotation = annotation;

        userAnnotationView.enabled = YES;
        userAnnotationView.animatesDrop = NO;
        userAnnotationView.pinColor = MKPinAnnotationColorPurple;
        userAnnotationView.canShowCallout = YES;
        [self performSelector:@selector(openCallout:) withObject:annotation afterDelay:0.01];

        return userAnnotationView;  
    }

Thanks for any advise. Cheers, Christian

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

相对绾红妆 2024-09-13 02:50:06

好的,所以我最终删除了自定义通知,但添加了自动弹出的调用。像这样:

mapView.showsUserLocation=TRUE;
mapView.userLocation.title = NSLocalizedString (@"Here am I",@"Here am I" );
[self performSelector:@selector(openCallout:) withObject:mapView.userLocation afterDelay:3.0];

和:

- (void)openCallout:(id<MKAnnotation>)annotation {
    [mapView selectAnnotation:annotation animated:YES];
}

如果没有延迟,调出将不会显示。

OK, so I ended up deleting the custom notification but adding a call out that pops up automatically. Like this:

mapView.showsUserLocation=TRUE;
mapView.userLocation.title = NSLocalizedString (@"Here am I",@"Here am I" );
[self performSelector:@selector(openCallout:) withObject:mapView.userLocation afterDelay:3.0];

and:

- (void)openCallout:(id<MKAnnotation>)annotation {
    [mapView selectAnnotation:annotation animated:YES];
}

Without the delay the call-out will not show up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文