showUserLocation 在 iPhone 模拟器中返回图钉而不是蓝点

发布于 2024-08-13 19:17:10 字数 744 浏览 5 评论 0原文

这是我的 -mapView:viewForAnnotation 方法,当我创建注释视图时,该方法会丢弃图钉。但是当我在 -viewDidLoad 中设置 mapView.showsUserLocation = YES; 时,我在无限循环中看到了一个引脚掉落(预期 - 在模拟器中),而不是正常的蓝点。

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
     MKAnnotationView *anno = nil;
     //create a pin annotation view
MKPinAnnotationView  *pin=[[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pin"]autorelease];

    [pin setPinColor:MKPinAnnotationColorRed];
    pin.animatesDrop=YES;
    pin.canShowCallout = YES;
    pin.calloutOffset = CGPointMake(-5, 5);
    anno = pin;
    return anno;
}

我怎样才能让它放下别针并显示蓝点?

谢谢

This is my -mapView:viewForAnnotation method which drops pins when i create annotation views. But when i set mapView.showsUserLocation = YES; in -viewDidLoad, i get a pin dropped on Infinite Loop (expected - in simulator) and not the normal blue dot.

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{
     MKAnnotationView *anno = nil;
     //create a pin annotation view
MKPinAnnotationView  *pin=[[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pin"]autorelease];

    [pin setPinColor:MKPinAnnotationColorRed];
    pin.animatesDrop=YES;
    pin.canShowCallout = YES;
    pin.calloutOffset = CGPointMake(-5, 5);
    anno = pin;
    return anno;
}

How can i get it to drop pins and show the blue dot as well?

Thanks

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

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

发布评论

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

评论(3

心不设防 2024-08-20 19:17:10

修复起来非常简单,尽管不确定这是否是正确的方法......

if (annotation == mapView.userLocation){
    return nil; //default to blue dot
}

Really simple to fix, although unsure if this is the correct way to do it...

if (annotation == mapView.userLocation){
    return nil; //default to blue dot
}
橪书 2024-08-20 19:17:10

与其他答案类似,这里有一些接近的内容:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{
    NSString *annotationType = [NSString stringWithCString:object_getClassName(annotation)];
    if ([annotationType compare:@"NSKVONotifying_MKUserLocation"] == 0)
        return nil;
    ...
}

当然,使用这样的东西需要您自担风险。如果苹果决定更改该名称,它可能会在明天停止工作。

Similar to the other answer, here's something close:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{
    NSString *annotationType = [NSString stringWithCString:object_getClassName(annotation)];
    if ([annotationType compare:@"NSKVONotifying_MKUserLocation"] == 0)
        return nil;
    ...
}

Of course, use something like this at your own risk. It could stop working tomorrow if Apple decided to change that name.

妥活 2024-08-20 19:17:10

通常,您使用自己的注释类来查找与注释相关的信息。在这种情况下,要仅处理您自己的注释,请使用类似

if ([annotation isKindOfClass:[MapLocation class]]) {}

Often you use your own class of annotation to look up information related to the annotation. In that case, to only handle your own annotations, use something like

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