3

マップビューを読み込んでいます。そして、アドレス帳の連絡先の住所に基づいて、地図にピンを追加しています。一部のピン(おそらく10個中2個)がマップビューにドロップしないという奇妙なケースがあります。有効な住所を確認しました。しかし、ピンは落ちていません。これの理由は何でしょうか。

    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
                }
                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];}
                                    }
            }
        }
        CFRelease(addressProperty);

    }

編集:私は自分の質問を編集していて、より具体的にしています。このコードを使用して、mapViewにピンをドロップしています。私のMacPCで、マップにドロップするピンが20個ある場合。20本のピンはすべて正確に落下し、正常に機能しています。しかし、iPhoneやiPadを使用していると、ピン数が大幅に減少します。つまり、私がドロップしている約20本のピンのうち、4本のピンだけがマップに表示されています。その理由がわかりません。

4

2 に答える 2

2

このコード:

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];
    }
}

意味がありません。


このメソッドは、オブジェクトではなく、オブジェクトdequeueReusableAnnotationViewWithIdentifierをデキューするためのものです。MKAnnotationViewid<MKAnnotation>

とにかく、デキューコードはviewForAnnotationここではなく、デリゲートメソッドに属します。

ここでは、注釈オブジェクト(MyAddressAnnotation)を作成して呼び出すだけaddAnnotationです。

また、アノテーション変数の名前を別の名前に変更addAnnotationして、マップビューのメソッドと混同しないようにすることを強くお勧めしますaddAnnotation

于 2012-03-27T12:32:41.583 に答える
0

私の悪い。私が使用する「fulladdress」文字列(streetNameとcityNameの間)では、スペースまたは「、」または「/」で区切られていませんでした。したがって、一部のアドレスが認識されていませんでした。

于 2012-04-17T05:19:12.050 に答える