@R:Code Shop @SW:Geocoding for the iPhone @D:Real-time geocoding services for iPhone @T:Cartography @V:We'll show you how to add location awareness to your iPhone apps. @A:By George F. Frazier @KT:Listing 1: The Short Leash App @LI: ----------------- ShortLeashViewController.h -------- #import // CoreLocationDelegate contains code to handle location services (i.e. GPS) #import "CoreLocationDelegate.h" #import @interface ShortLeashViewController: UITableViewController { CoreLocationDelegate *cLocation; MKReverseGeocoder *reverseGeo; } @end ----------------- ShortLeashViewController.m -------- #import "ShortLeashViewController.h" @implementation ShortLeashViewController #define CheckInNow 0 #define CallHomeNow 1 ... // // Invoked by the table view when user taps on a row. // We have two rows, "Check In Now!" and "Call Home Now!" // - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { CLLocationCoordinate2D *here; if (CheckInNow == [indexPath row]) { // getCurrentLocation returns the last location // fix that you stashed while listening for location changes here = [cLocation getCurrentLocation]; if (!here){ // we don't have a valid location, ask your object // to find a new one and make sure to let the user // know this might take a while [cLocation stirUpANewLocation]; return; } reverseGeo = [[MKReverseGeocoder alloc] initWithCoordinate:here]; if (reverseGeo) { reverseGeo.delegate = self; [reverseGeo start]; } } // Call Home else { [self CallHomeNow]; } // Fade the selection [self performSelector:@selector(deselect:) withObject:nil afterDelay:0.5f]; } - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error { [reverseGeo release]; } - (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark { [reverseGeo release]; NSString *msg = [NSString stringWithFormat:@"I\'m at %@ in %@, %@. ET has phoned home, happy now?", placemark.thoroughfare, placemark.administrativeArea, placemark.postalCode]; [self sendSMS:msg]; [msg release]; } - (void) CallHomeNow { ... } - (void) sendSMS:(NSString *)msg { ... } ... @end @KE: