0
CLLocationManagerDelegateを使用して正常に動作していたボタンのクリックでジオコードを逆にしました。しかし今、私はUISearchBarを使ってユーザーから名前を取得し、ボタンをクリックすると、ユーザーが入力した場所とマーカーが表示されます。 ジオコーディングに時間がかかるので、場所に値は保存されませんが、アプリはその作業を終了します。 誰も私にそれをする方法を教えてもらえますか?どこか間違っていると私を訂正してください。単一アプリケーションでの順方向ジオコーディングと逆方向ジオコーディング:必要な方向
- (IBAction)searchLocation:(id)sender {
NSString *address = self.searchBar.text;
NSLog(@"%@",address);
[forwardGeocoder geocodeAddressString:address completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
if ([placemarks count]>0) {
CLPlacemark *placeMarkForward = [placemarks objectAtIndex:0];
locationValue = placeMarkForward.location;
NSLog(@"Location : :%@",locationValue);
}
}];
[reverseGeocoder reverseGeocodeLocation:locationValue completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
if (error == nil && [placemarks count]>0) {
CLPlacemark *placeMarkReverse = [placemarks lastObject];
CLLocation *currentLocation;
marker.position = CLLocationCoordinate2DMake(currentLocation.coordinate.latitude,currentLocation.coordinate.longitude);
marker.title = [NSString stringWithFormat:@"%@",placeMarkReverse.country];
marker.snippet = [NSString stringWithFormat:@"%@\n%@", placeMarkReverse.locality,placeMarkReverse.postalCode];
marker.map = mapView_;
}
}];
}