2011-09-23 5 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 
} 
관련 문제