1
충돌 로그를 이해하려고합니다. CLLocationDistance
방법 distanceFromLocation
을 수행하려고 할 때 발생합니다. 지오 코딩해야하는 두 위치를 가져 오려면 하나의 블록이 필요하므로이 두 인스턴스 변수를 가질 수 있습니다. 그래서 매개 변수 방법에 직접 : 그것은 distanceFromLocation 부분에 EXC_BAD_ACCESS (code =EXC_ARM_DA_ALIGN, address=.....etc....)
을 제공합니다/충돌충돌 로그를 이해하지 못 했습니까?
- (void)geoCodeSetup:(NSArray *)placemarks :(NSError *)error andIdentifier:(NSString *)string {
CLLocation *location1;
CLLocation *location2;
if ([string isEqualToString:@"Origin"]) {
if (!error) {
CLPlacemark *place = [placemarks objectAtIndex:0];
CLLocation *location = place.location;
location1 = [[CLLocation alloc] initWithLatitude:location.coordinate.latitude longitude:location.coordinate.longitude];
} else {
NSString *string = [NSString stringWithFormat:@"%@ - also make sure you have inputted a valid city", [error localizedDescription]];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:string delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
}
}
if ([string isEqualToString:@"Destination"]) {
if (!error) {
CLPlacemark *place = [placemarks objectAtIndex:0];
CLLocation *location = place.location;
location2 = [[CLLocation alloc] initWithLatitude:location.coordinate.latitude longitude:location.coordinate.longitude];
} else {
NSString *string = [NSString stringWithFormat:@"%@ - also make sure you have inputted a valid city", [error localizedDescription]];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:string delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alert show];
}
}
CLLocationDistance distanceM = [location1 distanceFromLocation:location2];
[metreDistance setText:[NSString stringWithFormat:@"%f", distanceM]];
}
- (IBAction)calculateDistance {
[textFieldDestination resignFirstResponder];
NSString *origin = [textFieldOrigin text];
if (origin) {
CLGeocoder *geoCode = [[CLGeocoder alloc] init];
[geoCode geocodeAddressString:origin completionHandler: ^(NSArray *placemarks, NSError *error) {
NSArray *p1 = placemarks;
NSError *e1 = error;
[p1 retain];
[e1 retain];
[self geoCodeSetup:p1 :e1 andIdentifier:@"Origin"];
}];
}
NSString *destination = [textFieldDestination text];
if (destination) {
CLGeocoder *geoCode2 = [[CLGeocoder alloc] init];
[geoCode2 geocodeAddressString:destination completionHandler:^(NSArray *placemarks, NSError *error) {
NSArray *p2 = placemarks;
NSError *e2 = error;
[p2 retain];
[e2 retain];
[self geoCodeSetup:p2 :e2 andIdentifier:@"Destination"];
}];
}
. 오류 로그의 스크린 샷을 첨부했습니다.
무엇이 발생할 수 있습니다이며 어떻게 해결합니까?
예. location1 && location2가 0이 아닌 메소드를 기록한 경우 표시되지 않습니다 ... 오류가 발생하여 별도의 if (오류) 문에 오류가 발생했습니다. – MCKapur
이제 충돌이 없습니다. btw ..... – MCKapur
하지만 텍스트가 설정되어 있지 않습니다. 도 수정되었습니다. – MCKapur