【问题标题】:Show current position annotation by default默认显示当前位置标注
【发布时间】:2012-05-20 07:11:21
【问题描述】:

我在 mapkit 中显示了一个当前位置注释(蓝点)。贴上蓝点后显示注释, 我怎样才能在默认情况下显示注释?,当我启动视图时?不用敲击别针。

 - (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views {
    for(MKAnnotationView *annotationView in views) {
        if(annotationView.annotation == mv.userLocation) {

            self.mapView.userLocation.title= @"Current";
            self.mapView.userLocation.subtitle= @"Location";

            MKCoordinateRegion region;
            MKCoordinateSpan span;

            span.latitudeDelta=0.002;
            span.longitudeDelta=0.002; 

            CLLocationCoordinate2D location=mv.userLocation.coordinate;

            region.span=span;
            region.center=location;

            [mv setRegion:region animated:YES];
            [mv regionThatFits:region];

        }
    }

}

【问题讨论】:

  • 您的代码有效吗?少了一些东西,比如 mapView addAnnotation 来调用它……哦,对了,没有意识到 showUserLocation 确实和 addAnnotation 一起工作。

标签: ios annotations mapkit default show


【解决方案1】:

在这种情况下,selectAnnotation 应该可以工作,不是吗?稍等片刻后执行Selector。

....与之前相同的代码,但插入:

            id annotation = annotationView.annotation;
            [self performSelector:@selector(selectUserLocation:) withObject:annotation afterDelay:0.1f];
        }
    }
}

- (void)selectUserLocation:(id)annotation{
    [self.mapView selectAnnotation:annotation animated:YES];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-10
    • 1970-01-01
    • 1970-01-01
    • 2019-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多