MKAnnotationView问题我的引脚最初出现然后消失了吗?

时间:2012-10-11 19:07:39

标签: iphone ios mkmapview ios6 mkannotationview

我正在尝试使用我的代码调试问题,其中我的MKAnnotationView上的引脚最初在第一次调用时显示,但是当地图放大该位置时,除用户位置之外的所有注释都会消失。有人能指出我的逻辑缺陷吗?

以下是使用的代码。 AddPlacemark用于获取所有注释的位置,然后MKAnnotationView应在地图上显示所有注释。就像我说的那样,当地图首次出现时,所有的注释都会显示,但是当地图放大用户的位置时,我的所有其他注释都会消失。我相信只有当我更新我的Xcode以便我可以在iOS 6上测试并获得iPhone 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;
    }

1 个答案:

答案 0 :(得分:0)

这个问题实际上并非由于应用中的错误代码造成的。对于那个很抱歉!事实证明,我的后端代码将信息提供给此逻辑是不好的。