0

I am loading a mapview, with pins. The pins drop on the location, based on the address of a person from the addressbook. If the person has one address, then the map is loading fine. BUt if he has multiple addresses, then only one address location is shown on the map. But the code executes to load all the address locations of the person in the addressbook. Here is what I have done.

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
}

Edit: When I NSLog address, I get all the addresses in the addressbook. And when I debug, the code to load mapview is executed in all address cases. But in the map, only one pin(first address of the person) is loaded. Any suggestions?

Xavi Valero
  • 2,047
  • 7
  • 42
  • 80

1 Answers1

1

Your second address doesn't load because of the condition if(addAnnotation == nil) in -(void)displayMYMap. As your first annotation is done, addAnnotation is not nil anymore. Change the condition and check

Jean Paul
  • 2,389
  • 5
  • 27
  • 37