2012-03-27 3 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

지도를 더 빠르게 만들 수있는 방법이 있습니까? 지금은로드가 너무 느립니다. –

관련 문제