Created
June 30, 2014 04:54
-
-
Save bennythemink/53ec62d892e879904e25 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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