我正在加载地图视图。我正在根据通讯录中联系人的地址向地图添加图钉。我遇到了一些奇怪的情况,其中一些图钉(可能是 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 上放置图钉。在我的 Mac PC 上,如果要在地图中放置 20 个图钉。所有 20 个引脚都准确下降并且工作正常。但是当我使用 iPhone 或 iPad 时,引脚数会大大减少。也就是说,在我丢弃的大约 20 个图钉中,只有 4 个图钉显示在地图上。我无法找出原因。