Only a limited number of contacts are displayed on a mobile device, compared to a PC

I'm uploading a map. And I add pins to the map based on the address of the contacts in the address book. I have some weird cases where some contacts (maybe 2 out of 10) are not thrown onto the card. I have verified the address which is valid. But the pin doesn't fall off. What could be the reason for this.

    for (i = 0; i<[groupContentArray count]; i++) {
        person = ABAddressBookGetPersonWithRecordID(addressbook,[[groupContentArray objectAtIndex:i] intValue]);
        ABMultiValueRef addressProperty = ABRecordCopyValue(person, kABPersonAddressProperty);
        NSArray *address = (NSArray *)ABMultiValueCopyArrayOfAllValues(addressProperty);
        NSLog(@"Address %@", address);
        for (NSDictionary *addressDict in address) 
            addAnnotation = nil;
            firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty); 
            lastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty); 

            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];
            mapCenter = [self getLocationFromAddressString:fullAddress];
            if(stateName != NULL || country != NULL || streetName != NULL || cityName != NULL){

                if ((mapCenter.latitude == 0) && (mapCenter.longitude == 0))
                    // Alert View
                addAnnotation = (MyAddressAnnotation *)[mapView dequeueReusableAnnotationViewWithIdentifier:[groupContentArray objectAtIndex:i]];

                if(addAnnotation == nil){
                    addAnnotation = [[[MyAddressAnnotation alloc] initWithCoordinate:mapCenter title:firstName SubTitle:lastName Recordid:[groupContentArray objectAtIndex:i] ]autorelease];

                    [mapView addAnnotation:addAnnotation];}



Edit: I am editing my question and will be more specific. I am using code to delete contacts on my mapView. On my Mac PC if 20 contacts are dropped on the card. All 20 pins drop accurately and work fine. But when I use IPhone or iPad, the number of contacts decreases. That is, out of 20 pins that I throw, only 4 contacts are displayed on the map. I cannot understand the reason for this.


source to share

2 answers

My bad one. The "fulladdress" line (between streetName and cityName) that I use was not separated by a space or "," or "/". Therefore, some addresses were not recognized.



This code:

else {
    addAnnotation = (MyAddressAnnotation *)[mapView dequeueReusableAnnotationViewWithIdentifier:[groupContentArray objectAtIndex:i]];

    if (addAnnotation == nil) {
        addAnnotation = [[[MyAddressAnnotation alloc] initWithCoordinate:mapCenter title:firstName SubTitle:lastName Recordid:[groupContentArray objectAtIndex:i] ]autorelease];

        [mapView addAnnotation:addAnnotation];


doesn't make sense.

The method dequeueReusableAnnotationViewWithIdentifier

is for deleting object MKAnnotationView

objects - not id<MKAnnotation>


The dequeuing code belongs to the delegate method viewForAnnotation

anyway, not here.

Here you should just create your annotation objects ( MyAddressAnnotation

) and call addAnnotation


I also highly recommend that you change the name of your annotation variable from addAnnotation

to something else so you can't confuse it with the map view method addAnnotation




All Articles