2012-03-27 12 views
3

マップビューをロードしています。そして私はアドレス帳の連絡先のアドレスに基づいて、地図にピンを追加しています。私はいくつかのピン(おそらく2のうちの2つ)がマップビューにドロップしないいくつかの奇妙なケースを抱えています。私は有効なアドレスを確認しました。しかしピンは落ちていません。これの理由は何でしょうか。モバイルデバイスには、PCと比較して限られた数のピンしか表示されていません

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のピンを落とすコードを使用しています。私のMacのPC上で、20ピンがマップにドロップされる場合。 20ピンすべてが正確に落ちていて、正常に動作しています。しかし、私がIPhoneまたはIPadを使用しているとき、ピン数は大幅に減少します。つまり、私が落としている20ピンのうち、4ピンしか地図に表示されていません。私はこれの理由を理解することができません。

+0

コーディングの一部を表示できますか? – HarshIT

+0

あなたのコードがないと、私は何が間違っているかを言うことは不可能だと確信しています。言い換えれば、コードなどの情報を提供してください。 – Manuel

+0

ハドリーと完全に同意します...コード化されたものを提供してください。 – Krunal

答えて

0

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

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

は意味がありません。ないid<MKAnnotation>オブジェクト -


dequeueReusableAnnotationViewWithIdentifier方法はMKAnnotationViewオブジェクトをデキューするためのものです。

デキューコードは、とにかくviewForAnnotationデリゲートメソッドに属しますが、ここには含まれません。

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

また、私は非常には、マップビューのメソッドaddAnnotationと混同することはできませんので、あなたが何か他のものにaddAnnotationからあなた注釈変数の名前を変更するお勧めします。

+0

マップの読み込みを高速化するためにできることはありますか?今はロードするのが遅すぎます。 –

関連する問題