0

我正在开发一个从用户那里获取两个位置的 iPhone 应用程序。我想执行两次地理编码迭代,但我的代码运行第一次地理编码,但从不执行第二次。

我现在没有使用 for 循环,只想让地理编码运行两次并将坐标打印到两个不同的 UILabel。

我错过了什么?

- (IBAction)fetchCoordinates:(id)sender {
if (!self.geocoder) {
    self.geocoder = [[CLGeocoder alloc] init];
}

NSString *address1 = [NSString stringWithFormat:@"%@", self.yourLocation.text];
NSString *address2 = [NSString stringWithFormat:@"%@", self.theirLocation.text];

[self.geocoder geocodeAddressString:address1 completionHandler:^(NSArray *placemarks, NSError *error) {
    if ([placemarks count] > 0) {
        CLPlacemark *placemark = [placemarks objectAtIndex:0];
        CLLocation *location = placemark.location;
        CLLocationCoordinate2D coordinate = location.coordinate;

    self.coordinatesLabel1.text = [NSString stringWithFormat:@"%f, %f", coordinate.latitude, coordinate.longitude];
    }
}];

[self.geocoder geocodeAddressString:address2 completionHandler:^(NSArray *placemarks, NSError *error) {
    if ([placemarks count] > 0) {
        CLPlacemark *placemark = [placemarks objectAtIndex:0];
        CLLocation *location = placemark.location;
        CLLocationCoordinate2D coordinate = location.coordinate;

    self.coordinatesLabel2.text = [NSString stringWithFormat:@"%f, %f", coordinate.latitude, coordinate.longitude];
    }
}];

}

@end
4

0 回答 0