首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >userLocation引脚iPhone的MKAnnotationView

userLocation引脚iPhone的MKAnnotationView
EN

Stack Overflow用户
提问于 2010-12-31 12:52:59
回答 2查看 2.7K关注 0票数 0

我有一个使用MKMapView的应用程序,在应用程序中的某个点上,我需要使用移除地图中的所有当前图钉

代码语言:javascript
复制
[mapView removeAnnotations:mapView.annotations]

然后,我想再次显示当前用户的位置

代码语言:javascript
复制
mapView.showUserLocation = YES

但是我只能让它作为一个普通的别针重新出现,因为userLocation视图类不是公共的,所以我不能返回该类型的视图。以下是我的代码

代码语言:javascript
复制
- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id<MKAnnotation>)annotation

MKPinAnnotationView* annView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"currentloc"];

if (!annView) {
   MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
  annView.pinColor = MKPinAnnotationColorRed;
  annView.animatesDrop=TRUE;
  annView.canShowCallout = YES;
  annView.calloutOffset = CGPointMake(-5, 5);
  if ([annotation isKindOfClass:[DraggableAnnotationAM class]] ) annView.draggable =YES;
  return annView;

}
else {
  if ([annotation isKindOfClass:[DraggableAnnotationAM class]] ) annView.draggable =     YES;
  annView.annotation = annotation;
  return annView;
 }

我也通过反思发现,

代码语言:javascript
复制
MKUserLocationView

是用于显示当前位置的类,但因为它不是公共的,所以使用它不安全,而且我的应用程序总是崩溃,我相信有更简单的方法。

有没有可能做我想做的事情,或者我永远不应该删除mapView的用户位置注释?

提前感谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-01-02 09:38:16

尝试使用NSMutableArray来完成此操作。希望这能帮助你解决你的问题!

代码语言:javascript
复制
 NSMutableArray *annotation = [[NSMutableArray alloc] init];
 for (id <MKAnnotation> annot_ in [mapView annotations])
 {
     if ( [annot_ isKindOfClass:[MKUserLocation class]] ) {
     }
     else {
         [annotation addObject:annot_];
     }
 }

 [mapView removeAnnotations:annotation];   
 [annotation release];   
 annotation = nil;
票数 0
EN

Stack Overflow用户

发布于 2017-01-19 06:16:00

如果您只想显示用户位置的蓝点,而不是常规的别针,则在此mapView委托函数中返回nil。或者返回您自己的MKAnnotationView (子类)对象:

代码语言:javascript
复制
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
        if annotation is MKUserLocation {
            return nil // or return a custom MKAnnotationView
        } else { // etc.
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4568148

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档