2014-04-24 2 views
0

MapView에 여러 개의 주석이 있으며, 3 가지 배열로 나열되어 있습니다. 주석의 발신음을 변경하려면 - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 메소드를 사용했습니다.사용자 위치가 주석처럼 표시됩니다.

이상한 점은 내 UserLocation이 Customized Annotation으로 변경된다는 것입니다. 그 이유는 무엇이며 문제가 될 수 있습니까?

내 방법이 설정되는 방법
myAnn = [[Annotations alloc]init]; 
location.latitude = 52.338847; 
location.longitude = 4.937482; 
myAnn.coordinate = location; 
myAnn.title = @"Afvalpunt"; 
myAnn.subtitle = @"Rozenburglaan 1"; 
[category3 addObject:myAnn]; 

[self.locationArrays addObject:category3]; 

self.currentAnnotation = 0; 

[self.myMapView addAnnotations:[self.locationArrays objectAtIndex:0]]; 

:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation { 

    MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"MapAn"]; 
    if (!annotationView) { 
     annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MapAn"]; 
     annotationView.canShowCallout = YES; 

     //Blauw Navigatie Auto... 
     UIImageView *carView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Driving"]]; 
     UIButton *blueView = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44+30)]; 
     blueView.backgroundColor = [UIColor colorWithRed:0 green:0.5 blue:1 alpha:1]; 
     carView.frame = CGRectMake(11, 14, carView.image.size.width, carView.image.size.height); 
     [blueView addTarget:self action:@selector(carClicked) forControlEvents:UIControlEventTouchUpInside]; 
     [blueView addSubview:carView]; 
     annotationView.leftCalloutAccessoryView = blueView; 
    } 
    return annotationView; 
} 
+0

내 대답을 확인이 코드를 사용해보십시오. –

+0

내 대답을 만족하면 내 대답을 upvote하시기 바랍니다. –

+0

나는 남자를 알고, 단지 50 초 남았습니다;) – SwingerDinger

답변

1

이 코드를 시도

는 내 주석을 나열하는 방법. 주석지도보기 화면을 파란색 점 & 원 애니메이션을 수 있도록 userLocation 경우
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { 

    if (annotation == mapView.userLocation) return nil; 
    ... 

우리는 전무 돌아갑니다. userLocation에 대한 맞춤 주석을 표시하려면 return nil; 행을 삭제하고 맞춤 설정을 수행하십시오.

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { 

static NSString* AnnotationIdentifier = @"Annotation"; 
MKPinAnnotationView *pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier]; 

if (!pinView) { 

    MKPinAnnotationView *customPinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease]; 
    if (annotation == mapView.userLocation) 
    { 
     customPinView.image = [UIImage imageNamed:@"myCarImage.png"]; 
    } 
    else 
    { 
     customPinView.image = [UIImage imageNamed:@"mySomeOtherImage.png"]; 
     customPinView.animatesDrop = NO; 
     customPinView.canShowCallout = YES; 
     return customPinView; 
    } 
    else 
    { 
     pinView.annotation = annotation; 
    } 

    return pinView; 
} 

희망이 코드가 유용합니다.

+0

답변과 설명 남자 주셔서 감사합니다! – SwingerDinger

1

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation 
{ 
    if ([annotation isKindOfClass:[MKUserLocation class]] || annotation==mapView.userLocation) 
    { 
     return nil;//Here you can also customise your pin if you dont want pin then just return nil. 
    } 
    else 
    { 
    //your code 
    } 
} 
+0

답변 해 주셔서 감사합니다! – SwingerDinger