与PC相比,移动设备中仅显示有限数量的引脚

时间:2012-03-27 12:10:40

标签: iphone ios mkmapview pins

我正在加载地图视图。我根据地址簿中的联系人地址将地图添加到地图中。我有一些奇怪的情况,其中一些引脚(可能是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个引脚。我无法找出原因。

2 个答案:

答案 0 :(得分: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混淆。

答案 1 :(得分:0)

我的坏。在我使用的“完整地址”字符串(街道名称和城市名称之间)中,没有用空格或“,”或“/”分隔。因此,有些地址没有得到承认。