2011-09-23 12 views
11

MKMapViewに現在の位置が表示されるように設定しました。私はまた、他のピンのために実装されたカスタムピンを持っています。しかし、現在の場所がカスタムピンとして表示されているのに対し、私はそれが通常の青い円(Googleマップのようなもの)になりたいと思っていました。MKMapView現在の位置がカスタムピンとして表示されます

私は自分のコードに次のように定義されています

- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation: (id<MKAnnotation>) annotation MKAnnotationView *pin = (MKAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier: @"VoteSpotPin"]; 
    if (pin == nil) 
    { 
     pin = [[[MKAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"TestPin"] autorelease]; 
    } 
    else 
    { 
     pin.annotation = annotation; 
    } 

    [pin setImage:[UIImage imageNamed:@"TestPin.png"]]; 
    pin.canShowCallout = YES; 
    pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
    return pin; 
} 

は、どのように私はピンとして表示するために現在の場所を防ぐことができますか?

+1

mapView.showsUserLocation = YES、それは現在の場所が表示されます。 – Srinivas

+0

私はそれをして、それは私が持っているカスタムピンとして現在の場所を示し、青い円ではありません。それは実際には実際の問題 – adit

+0

あなたのアプリケーションをチェックしているかどうかは、デバイスまたはシミュレータ – Srinivas

答えて

24

あなたはこれを実装する必要があります -

- (MKAnnotationView *) mapView: (MKMapView *) mapView viewForAnnotation:(id<MKAnnotation>) annotation 
{   
    if (annotation == mapView.userLocation) 
    { 
     return nil; 
    } 
    else 
    { 
     MKAnnotationView *pin = (MKAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier: @"VoteSpotPin"]; 
     if (pin == nil) 
     { 
      pin = [[[MKAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"TestPin"] autorelease]; 
     } 
     else 
     { 
      pin.annotation = annotation; 
     }   

     [pin setImage:[UIImage imageNamed:@"TestPin.png"]]; 
     pin.canShowCallout = YES; 
     pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
     return pin; 
    } 
} 
+1

でサポートされている場所のmanager.issue mapView.userLocationもアノテーションであることを知らなかった。ありがとう!これを知ってうれしい – adit

0
- (MKAnnotationView *)mapView:(MKMapView *)mapViewTmp viewForAnnotation:(id<MKAnnotation>)annotation 
    { 
     if(annotation == mapView.userLocation) 
      return nil; 
     else 
      { 
MKAnnotationView *pin = (MKAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier: @"VoteSpotPin"]; 
      if (pin == nil) 
      { 

       pin = [[[MKAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: @"TestPin"] autorelease]; 
      } 
      else 
      { 
       pin.annotation = annotation; 
      } 

      [pin setImage:[UIImage imageNamed:@"TestPin.png"]]; 
      pin.canShowCallout = YES; 
      pin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
      return pin; 
     } 

    } 
0

が最も簡単な解決策をしたいですか?オブジェクトピンをMKAnnotationViewからMKPinAnnotationViewに変更するだけで、目的のものが表示されます。スウィフトのために

0
mapView.delegate=self; 



MKCoordinateRegion myRegion; 

CLLocationCoordinate2D center; 

center.latitude=40.4000;//spean 

center.longitude=-3.6833;//firstLagi;//-5.345373; 



MKCoordinateSpan span; 

span.latitudeDelta=My_Span; 
span.longitudeDelta=My_Span; 


myRegion.center=center; 
myRegion.span=span; 


[mapView setRegion:myRegion animated:YES]; 



NSMutableArray *locations=[[NSMutableArray alloc]init]; 

CLLocationCoordinate2D location; 
Annotation *myAnn; 




allList=[[AllList alloc]init]; 




for (int j = 0; j<[appDelegate.allListArray count]; j++) 
{ 
    [email protected]"cat"; 
    myAnn=[[Annotation alloc]init]; 

    allList=[appDelegate.allListArray objectAtIndex:j]; 

    location.latitude=[allList.lati doubleValue]; 
    location.longitude=[allList.lagi doubleValue]; 

    myAnn.coordinate=location; 
    myAnn.title=allList.name; 
    //myAnn.subtitle=allList.type; 

    [locations addObject:myAnn]; 


} 

[self.mapView addAnnotations:locations]; 
2

:あなたはその注釈に現在位置の緯度と経度を通過し、現在の場所でピンを表示する.IF

if annotation is MKUserLocation { 
    return nil 
} 
関連する問題