1
내 MKAnnotationView의 핀이 첫 번째 호출에서 잠시 표시되는 코드에서 문제를 디버깅하려고 시도하지만 위치에서지도가 확대되면 사용자 위치를 제외한 모든 주석이 사라집니다. 누군가 내 논리의 결함을 지적 할 수 있습니까?MKAnnotationView 문제가 내 핀이 처음 나타나면 사라집니다.
아래는 사용중인 코드입니다. AddPlacemark는 모든 내 주석의 위치를 가져 오는 데 사용되며, MKAnnotationView는지도에 모든 주석을 표시해야합니다. 내가 말했듯이지도가 처음 나타날 때 주석이 모두 표시되지만지도가 사용자의 위치를 확대하면 다른 모든 주석이 사라집니다. 나는이 문제는 내가 아이폰 OS 6에 테스트하고이 질문은 실제로 응용 프로그램에서 나쁜 코드에 기인하지 않은 아이폰 5
- (void)AddPlacemark {
if([allplacemarkarray count]>0) {
[mapView removeAnnotations:allplacemarkarray];
[allplacemarkarray removeAllObjects];
}
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.2;
span.longitudeDelta=0.2;
CLLocationCoordinate2D location1;
location1.latitude = appdel.MyCurrentLocation.latitude;
location1.longitude = appdel.MyCurrentLocation.longitude;
region.span = span;
region.center = location1;
Placemark *addAnnotation = [[[Placemark alloc] initWithCoordinate:location1] retain];
[mapView addAnnotation:addAnnotation];
[allplacemarkarray addObject:addAnnotation];
[addAnnotation release];
if(alllocationArray) {
for(int i=0;i<[alllocationArray count];i++) {
NSDictionary *locationdict=[alllocationArray objectAtIndex:i];
CLLocationCoordinate2D location;
location.latitude = [[locationdict objectForKey:@"VLATITUDE"] floatValue];
location.longitude =[[locationdict objectForKey:@"LONGITUDE"]floatValue];
region.span=span;
region.center=location;
Placemark *addAnnotation = [[[Placemark alloc] initWithCoordinate:location] retain];
[allplacemarkarray addObject:addAnnotation];
addAnnotation.titletext = [locationdict objectForKey:@"NAME"];
addAnnotation.logoText = [locationdict objectForKey:@"LOGO"];
NSString *add1=[locationdict objectForKey:@"ADDR1"];
NSString *add2=[locationdict objectForKey:@"ADDR2"];
NSString *city=[locationdict objectForKey:@"CITY"];
NSString *state=[locationdict objectForKey:@"STATE"];
NSString *zip =[locationdict objectForKey:@"ZIP"];
addAnnotation.subtitletext=[NSString stringWithFormat:@"%@ %@ %@, %@ %@",add1,add2,city,state,zip];
[addAnnotation setPlacemarkId:[NSNumber numberWithInt:i]];
[mapView addAnnotation:addAnnotation];
[addAnnotation release];
}
[mapView setRegion:region animated:TRUE];
[mapView regionThatFits:region];
}
}
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(Placemark *) annotation {
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MyPin"];
annView.animatesDrop = TRUE;
annView.canShowCallout = YES;
[annView setSelected:YES];
UIImage *pinImage = [UIImage imageNamed:annotation.logoText];
UIImageView *logoView = [[UIImageView alloc] initWithImage:pinImage];
logoView.frame = CGRectMake(-23, -6, 63, 48);
UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
myDetailButton.frame = CGRectMake(0, 0, 23, 23);
myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[myDetailButton addTarget:self action:@selector(checkButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[myDetailButton setTag:[annotation.placemarkId intValue]];
annView.rightCalloutAccessoryView=myDetailButton;
if(annotation.coordinate.latitude == appdel.MyCurrentLocation.latitude && annotation.coordinate.longitude == appdel.MyCurrentLocation.longitude) {
annView.pinColor = MKPinAnnotationColorRed;
} else if ([annotation.logo isEqualToString:@""]) {
annView.pinColor = MKPinAnnotationColorPurple;
} else {
[annView addSubview:logoView];
}
annView.calloutOffset = CGPointMake(-5, 5);
return annView;
}
구현 된 - (void) mapView : (MKMapView *) mapView regionDidChangeAnimated : (BOOL) animated? – yunas
@yunas - 주석을 위해 mapView를 구현 한 이후 구현하지 않았습니다. 다른 mapView를 구현할 필요가 없다고 생각했습니다. 시도해보고 어떤 일이 발생했는지 알려줍니다. 응답 주셔서 감사합니다! –