0
기본적으로 MKMapView에 대한 위치 데이터베이스가 있으며 각 주석의 상세 공개 버튼을 탭하면 해당 위치에 대한 자세한 정보 (예 : 웹 사이트 및 전화 번호)가 표시됩니다 .수레에 대한 코어 - 데이터 술어 필터링
문제는 내 데이터베이스에서 일부 좌표가 6 대신 소수점 4 또는 5가 있기 때문에 버튼을 두드렸을 때 응용 프로그램이 중단됩니다. 이 문제를 막으려면 UIAlertView에 "추가 정보를 찾을 수 없습니다"라고 말하면서 추가했습니다. 더 나은 방법으로 내 조건자를 사용할 방법이 있습니까?
NSString *lat = [NSString stringWithFormat:@"%.6f", view.annotation.coordinate.latitude];
NSString *lon = [NSString stringWithFormat:@"%.6f", view.annotation.coordinate.longitude];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Stores" inManagedObjectContext:_managedObjectContext];
[request setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"Latitude == %@ && Longitude == %@", lat, lon];
[request setPredicate:predicate];
NSError *error = nil;
NSArray *stores = [_managedObjectContext executeFetchRequest:request error:&error];
[request release];
if (![stores count]) {
UIAlertView *alert = [[[UIAlertView alloc]initWithTitle:@"Error" message:@"Sorry, we are unable to locate more information for this location." delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles: nil]autorelease];
[alert show];
} else {
Stores *currentStore = [stores objectAtIndex:0];
NSLog(@"current store %@", currentStore);
AddressAnnotation *annotation = view.annotation;
MoreInfoTable *moreInfoView = [[MoreInfoTable alloc] initWithStyle:UITableViewStyleGrouped];
moreInfoView.currentStore = currentStore;
moreInfoView.managedObjectContext = self.managedObjectContext;
moreInfoView.title = annotation.title ;
moreInfoView.getWebsite =[NSURL URLWithString:annotation.website];
moreInfoView.getDirections = [NSURL URLWithString:[NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f", mapView.userLocation.coordinate.latitude, mapView.userLocation.coordinate.longitude, annotation.coordinate.latitude, annotation.coordinate.longitude]];
moreInfoView.footer = [NSString stringWithFormat:@"%.1f miles away", annotation.distanceFromLocation];
moreInfoView.address = annotation.address;
moreInfoView.getPhoneNumber = [NSMutableString stringWithString:annotation.phoneNumber];
moreInfoView.lat = view.annotation.coordinate.latitude;
moreInfoView.lon = view.annotation.coordinate.longitude;
[self.navigationController pushViewController:moreInfoView animated:YES];
[moreInfoView release];
}
}