加载到地图中,地址簿中一个人的多个地址



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

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地址时,我得到了地址簿中的所有地址。当我调试时,加载 mapview 的代码在所有地址情况下都会执行。但是在地图中,只加载了一个图钉(人的第一个地址)。有什么建议吗?

由于条件if(addAnnotation == nil) -(void)displayMYMap,您的第二个地址无法加载。当您的第一个注释完成时,addAnnotation不再是零。更改条件并检查

最新更新