I'm trying to add a placemark to a map. The placemark is built from an address completely outside of Address Book.
My placemark is appearing on the map, but when I try to pinch to zoom in I get a crash:
*** -[CALayer objectForKey:]: unrecognized selector sent to instance 0x4569dc0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[CALayer objectForKey:]: unrecognized selector sent to instance 0x4569dc0'
Here's how I'm setting up the address:
id theAddress = [NSDictionary dictionaryWithObjectsAndKeys:
[NSString stringWithFormat: @"%@ - %@", theAddress1 ? theAddress1 : @"", theAddress2 ? theAddress2 : @""], kABPersonAddressStreetKey,
theCity ? theCity : @"", kABPersonAddressCityKey,
theState ? theState : @"", kABPersonAddressStateKey,
theZip ? theZip : @"", kABPersonAddressZIPKey,
theCountry ? theCountry : @"", kABPersonAddressCountryKey,
nil];
I use the values in the address record to find the coordinate for the address (learned how to do this from this question & answer), then I add it to my map:
[mapView addAnnotation: [[[MKPlacemark alloc] initWithCoordinate: theCoordinate
addressDictionary: theAddress] autorelease]];
The crash definitely seems to be caused by this MKPlacemark, as if I comment out the addAnnotation statement the code doesn't crash.
Any idea what's going on? I'm guessing I haven't got enough in the address record, but the error message is really unhelpful.