我正在使用GMSAutocompleteViewController
在我的应用中获取位置,这使用户更容易,并且整洁到我的服务器数据。这是我的代码。
我的问题是我怎么能检测到自动完成返回没有结果所以我可以处理这个?
#pragma mark - GMSAutocompleteViewControllerDelegate
// Handle the user's selection.
- (void)viewController:(GMSAutocompleteViewController *)viewController didAutocompleteWithPlace:(GMSPlace *)place {
[self dismissViewControllerAnimated:YES completion:nil];
// Do something with the selected place.
[_institutionTextField setText:place.name];
[_addressTextField setText:[[place.addressComponents objectAtIndex:0] name]];
[errorStatus replaceObjectAtIndex:0 withObject:[NSNumber numberWithBool:YES]];
[errorStatus replaceObjectAtIndex:1 withObject:[NSNumber numberWithBool:YES]];
[experinceDictionary setObject:@{@"name":place.name,
@"latitude":[NSNumber numberWithFloat:place.coordinate.latitude],
@"longitude":[NSNumber numberWithFloat:place.coordinate.longitude],
@"address":place.formattedAddress,
@"google_place_id":place.placeID}
forKey:@"hospital"];
}
- (void)viewController:(GMSAutocompleteViewController *)viewController didFailAutocompleteWithError:(NSError *)error {
[self dismissViewControllerAnimated:YES completion:nil];
// TODO: handle the error.
NSLog(@"Error: %@", [error description]);
}
// User canceled the operation.
- (void)wasCancelled:(GMSAutocompleteViewController *)viewController {
[self dismissViewControllerAnimated:YES completion:nil];
}
// Turn the network activity indicator on and off again.
- (void)didRequestAutocompletePredictions:(GMSAutocompleteViewController *)viewController {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}
- (void)didUpdateAutocompletePredictions:(GMSAutocompleteViewController *)viewController {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
#pragma mark - UITextFieldDelegate
- (void)textFieldDidBeginEditing:(UITextField *)textField {
if (textField == _institutionTextField) {
GMSAutocompleteViewController *acController = [[GMSAutocompleteViewController alloc] init];
acController.delegate = self;
[self presentViewController:acController animated:YES completion:nil];
}
}