MKAnnotationView のピンが最初の呼び出しで最初に 2 秒間表示されるコードの問題をデバッグしようとしていますが、マップがその場所にズームインすると、ユーザーの場所を除くすべての注釈が消えます。誰かが私の論理の欠陥を指摘できますか?
以下は、使用されているコードです。AddPlacemark を使用してすべての注釈の場所を取得すると、MKAnnotationView がそれらをすべて地図上に表示する必要があります。私が言ったように、地図が最初に表示されるときはすべての注釈が表示されますが、地図がユーザーの場所にズームインすると、他のすべての注釈が消えます。この問題は、iOS 6 でテストして iPhone 5 用のシミュレーターを入手できるように Xcode を更新したときにのみ発生し始めたと思います。
- (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;
}