我正在加载一个带有引脚的mapview。根据地址簿中某人的地址,引脚会在该位置上掉落。如果此人有一个地址,那么地图正在加载正常。如果他有多个地址,那么就会在地图上显示一个地址位置。但是代码执行以加载地址簿中人员的所有地址位置。这就是我所做的。
for (NSDictionary *addressDict in address)
{
firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
lastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
// contactName = [firstName stringByAppendingString:lastName];
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];
NSLog(@"full address %@", fullAddress);
mapCenter = [self getLocationFromAddressString:fullAddress];
if(stateName != NULL || country != NULL || streetName != NULL || cityName != NULL){
if ((mapCenter.latitude == 0) && (mapCenter.longitude == 0))
{
// Alert view
}
else{
addressFieldSearchBar.text = fullAddress;
[NSThread detachNewThreadSelector:@selector(displayMYMap) toTarget:self withObject:nil];
}
}
}
-(void)displayMYMap
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
MKCoordinateRegion region = mapView.region;
MKCoordinateSpan span;
span.latitudeDelta=100;
span.longitudeDelta=100;
if(addAnnotation == nil){
if([firstName length] < 1 && [lastName length] < 1){
firstName = @"No Name";
lastName = @"";
}
else if([firstName length] < 1){
firstName = lastName;
}
addAnnotation = [[[MyAddressAnnotation alloc] initWithCoordinate:mapCenter title:firstName SubTitle:lastName Recordid:passedRecordID]autorelease];
[mapView addAnnotation:addAnnotation];
}
else{
// Alert view
}
编辑:当我的NSLog地址时,我得到了地址簿中的所有地址。当我调试时,加载mapview的代码在所有地址情况下执行。但是在地图中,只加载了一个引脚(人的第一个地址)。有什么建议吗?
答案 0 :(得分:1)
由于if(addAnnotation == nil)
中的条件-(void)displayMYMap
,您的第二个地址无法加载。当您的第一个注释完成后,addAnnotation
不再是零。更改条件并检查