代码之家  ›  专栏  ›  技术社区  ›  Christian Loncle

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

  •  9
  • Christian Loncle  · 技术社区  · 16 年前

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

    我想为用户在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;  
        }
    

    谢谢你的建议。干杯,克里斯蒂安

    1 回复  |  直到 8 年前
        1
  •  7
  •   David Prem Acharya    8 年前

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

    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];
    }
    

    如果不延迟,呼叫将不会出现。

    推荐文章