Skip to content

Instantly share code, notes, and snippets.

@bennythemink
Created June 30, 2014 04:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bennythemink/53ec62d892e879904e25 to your computer and use it in GitHub Desktop.
Save bennythemink/53ec62d892e879904e25 to your computer and use it in GitHub Desktop.
- (IBAction) didEnterSearchTerm:(id)sender {
if ([self.searchTxt.text length] == 0) return;
[self displayLoadingViewAndDisableUI];
// contact Apple for geocode
CLGeocoder *geoCoder = [[CLGeocoder alloc] init];
// User enters a search term (e.g. springfield united states of america) and Apple's server responds with an array of placemarks that
// match the entered search term.
[geoCoder geocodeAddressString:self.searchTxt.text completionHandler:^(NSArray *placemarks, NSError *error){
if (error) {
[[[UIAlertView alloc] initWithTitle:@"Error" message:[error description] delegate:nil cancelButtonTitle:nil otherButtonTitles:kAlertOkTitle, nil] show];
NSLog(@"error = %@",[error localizedDescription]);
[self hideLoadingViewAndEnableUI];
return;
}
if ([placemarks count] == 0) {
[[[UIAlertView alloc] initWithTitle:@"Warning" message:@"No location found for the supplied address! Please try another." delegate:nil cancelButtonTitle:kAlertOkTitle otherButtonTitles:nil, nil] show];
[self hideLoadingViewAndEnableUI];
return;
}
// only one placemark matches the entered address, do something with it.
else if ([placemarks count] == 1) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
// use placemark.
[self hideLoadingViewAndEnableUI];
}
else {
// multiple possible locations found, display them in a table for the user to select.
self.possiblePlacemarks = placemarks;
[self displayTableOfPossibleLocations];
}
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment