2010-12-31 12 views
0

のために、私はMKMapViewを使用するアプリケーションを持っているアプリの中でいくつかの点で私はMKAnnotationViewがuserLocationピンiPhone

[mapView removeAnnotations:mapView.annotations] 

を使用してマップ内のすべての現在のピンを削除する必要があります。そして、私は再び電流を表示したいですユーザーの場所

mapView.showUserLocation = YES 

しかし、私はだけなので、私はそのタイプのビューを返しカントuserLocationビュークラスのパブリックではないので、それは、通常のピンとして再表示させることができます。ここで

MKUserLocationView 

は、現在位置を表示するために使用されるクラスですが、それも、私はリフレクションを通じて発見した私のコード

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

でその使用が安全ではないと私のアプリの公開ではないので、クラッシュし続けているし、確かに簡単な方法です。

mapViewのユーザーの場所の注釈を削除しないでください。事前

答えて

0

おかげで、NSMutableArrayのでそれをやってみてください。これがあなたの問題解決に役立つことを願っています!

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; 
1

通常のピンの代わりにユーザーの位置に青い点を表示したい場合は、このmapView delegate関数でnilを返します。または、独自のMKAnnotationView(サブクラス)オブジェクトを返します。

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { 
     if annotation is MKUserLocation { 
      return nil // or return a custom MKAnnotationView 
     } else { // etc. 
関連する問題