Giving up on the Reverse Geocoding challenge for now


#1

I think I’ve got the right design to make it work, but there is something wrong with assigning the delegate. I used the CLLocationManager as a design pattern. Here is the relavent code:

WhereamiAppDelegate.h:

[code]#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>

// Challenge: Reverse Geocoding
// I’m using the WhereamiAppDelegate as the delegate for the ReverseGeocoding,
// so declare the delgate compliant with the protocol

@interface WhereamiAppDelegate : NSObject <UIApplicationDelegate, CLLocationManagerDelegate, MKMapViewDelegate, MKReverseGeocoderDelegate>
{
UIWindow *window;

CLLocationManager *locationManager;

IBOutlet MKMapView *ptrInstanceMapView;
IBOutlet UIActivityIndicatorView *activityIndicator;
IBOutlet UITextField *locationTitleField;

// We also declare a Geolocator object so we can get to it's methods
// and a variable to retain the location pointer while wait for the callback

MKReverseGeocoder *ptrGeocoder;
CLLocation *ptrLocation;

}

@property (nonatomic, retain) IBOutlet UIWindow *window;

  • (void)findLocation;
  • (void)foundLocation;

@end[/code]

And here is the problem code fragment from WhereamiAppDelegate.m:

[code]#import “WhereamiAppDelegate.h”
#import “MapPoint.h”

@implementation WhereamiAppDelegate

@synthesize window;

  • (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {

    // Create location manager object -
    locationManager = [[CLLocationManager alloc] init];

    // Make this instance of WhereamiAppDelegate the delegate
    // it will send its messages to our WhereamiAppDelegate
    [locationManager setDelegate:self];

    // Challenge: Reverse Geocoding
    // We also need to allocate the Reverse Geocoder object and
    // make WhereamiAppDelegate the delegate for it
    ptrGeocoder = [[MKReverseGeocoder alloc] init];
    [ptrGeocoder setDelegate:self];
    [/code]

As far as I can tell, I am assigning WhereamiAppDelegate to the Geocoder in the exact same way I am to the location manager. But where the locationManager has no issue, the ptrGeocoder delegation spits out an “Program received signal: “EXC_BAD_ACCESS”.”

I think it is time to move on to chapter 6, this chapter has been problematic.


#2

mkreversegeocoder is a single use object. after one use it no longer exists.


#3

I think you are along the right lines of what you are trying to do, but you might not be doing it in the right place.

Personally I did something similar but on the MapPoint class and not the WheramiAppDelegate.

I can post some code if you are still having problems though.

Something else that I used for this is that an MKAnnotation can have a subtitle as well as a title. So when I added the MKReverseGeocoder I put the information from this into a new property for subtitle.