2012-03-27 78 views
3

我正在加載地圖視圖。我正在根據地址簿中聯繫人的地址向地圖添加針腳。我遇到了一些奇怪的情況,其中一些針腳(可能是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 2012-03-27 12:13:53

+0

沒有你的任何代碼我很確定不可能說出什麼是錯的。換句話說:請提供一些更多的信息,如代碼。 – Manuel 2012-03-27 12:14:40

+0

完全同意哈德利...請提供你已編碼的東西。 – Krunal 2012-03-27 12:15:31

回答

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

是沒有意義的。


dequeueReusableAnnotationViewWithIdentifier方法是用於出列MKAnnotationView物體 - 不id<MKAnnotation>對象。

出隊代碼在viewForAnnotation委託方法屬於反正不是在這裏。

在這裏,你應該創建你的註釋對象(MyAddressAnnotation)並且在其上調用addAnnotation

我也強烈建議你從addAnnotation改變你的註釋變量的名稱到別的東西,所以你不能與地圖視圖的方法addAnnotation混淆。

+0

有什麼我可以做的,以加快地圖加載。現在加載速度太慢。 – 2012-03-27 14:52:55

相關問題