0

我正在加载带有图钉的地图视图。根据地址簿中某个人的地址,图钉落在该位置上。如果此人有一个地址,则地图加载正常。但是如果他有多个地址,那么地图上只会显示一个地址位置。但是代码会执行以加载地址簿中此人的所有地址位置。这是我所做的。

for (NSDictionary *addressDict in address) 
    {
        firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty); 
        lastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty); 
        // contactName = [firstName stringByAppendingString:lastName];
        NSString *country = [addressDict objectForKey:@"Country"];
        NSString *streetName = [addressDict objectForKey:@"Street"];
        NSString *cityName = [addressDict objectForKey:@"City"];
        NSString *stateName = [addressDict objectForKey:@"State"];

        if (streetName == (id)[NSNull null] || streetName.length == 0 ) streetName = @"";
        if (stateName == (id)[NSNull null] || stateName.length == 0 ) stateName = @"";
        if (cityName == (id)[NSNull null] || cityName.length == 0 ) cityName = @"";
        if (country == (id)[NSNull null] || country.length == 0 ) country = @"";

        NSString *fullAddress = [streetName stringByAppendingFormat:@"/%@/%@/%@", cityName, stateName, country];
       NSLog(@"full address %@", fullAddress);

        mapCenter = [self getLocationFromAddressString:fullAddress];
        if(stateName != NULL || country != NULL || streetName != NULL || cityName != NULL){

            if ((mapCenter.latitude == 0) && (mapCenter.longitude == 0))
            {
                //  Alert view                     
            }
            else{

            addressFieldSearchBar.text = fullAddress;
            [NSThread detachNewThreadSelector:@selector(displayMYMap) toTarget:self withObject:nil];
        }
        }
    }


-(void)displayMYMap
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

MKCoordinateRegion region = mapView.region; 
MKCoordinateSpan span; 
span.latitudeDelta=100; 
span.longitudeDelta=100; 


if(addAnnotation == nil){
    if([firstName length] < 1 && [lastName length] < 1){
        firstName = @"No Name";
        lastName = @"";
    }
    else if([firstName length] < 1){

        firstName = lastName;
    }

    addAnnotation = [[[MyAddressAnnotation alloc] initWithCoordinate:mapCenter title:firstName SubTitle:lastName Recordid:passedRecordID]autorelease];
    [mapView addAnnotation:addAnnotation];
}
else{
    //       Alert view
}

编辑:当我 NSLog 地址时,我得到地址簿中的所有地址。当我调试时,加载地图视图的代码在所有地址情况下都会执行。但是在地图中,只加载了一个引脚(人的第一个地址)。有什么建议么?

4

1 回答 1

1

由于. if(addAnnotation == nil)_ -(void)displayMYMap当您的第一个注释完成后,addAnnotation不再为零。更改条件并检查

于 2012-04-17T13:42:05.140 回答