objective c - Custom MKAnnotation always says it's an MKUserLocation class -


i have custom class called device implements mkannotation protocol. in examples i'm following (mapkit , core location on ipad o'reilly media), check if annotation want add mkuserlocation class , return nil if is. understand does, problem device class identified mkuserlocation returns nil never annotations added map. i've gone on code again , again , again. i've o'reilly code samples , can't see i'm going off. it's frustrating.

here's device.m:

@implementation device  @synthesize udid, user, latitude, longitude;  - (cllocationcoordinate2d)coordinate {     cllocationcoordinate2d internalcoordinate;      internalcoordinate.latitude = [self.latitude doublevalue];     internalcoordinate.longitude = [self.longitude doublevalue];      return internalcoordinate; }  - (nsstring *)title {     return self.user; }  - (nsstring *)subtitle {     return nil; }  - (id)initwithudid:(nsstring *)_udid user:(nsstring *)_user latitude:(nsnumber *)_latitude longitude:(nsnumber *)_longitude {     if (self == [super init]) {         self.udid = _udid;         self.user = _user;         self.latitude = _latitude;         self.longitude = _longitude;     }      return self; }  - (void)dealloc {     [udid release];     self.udid = nil;      [user release];     self.user = nil;      [latitude release];     self.latitude = nil;      [longitude release];     self.longitude = nil;      [super dealloc]; }  @end 

and here's devicemapannotator.m:

@implementation devicemapannotator  - (mkannotationview *)mapview:(mkmapview *)mapview viewforannotation:(id <mkannotation>)annotation {     if ([annotation iskindofclass:[mkuserlocation class]]) {         nslog(@"annotation mkuserlocation class");          return nil;     }      mkpinannotationview *deviceannotationview = (mkpinannotationview *)[mapview dequeuereusableannotationviewwithidentifier:@"deviceannotation"];      if (deviceannotationview == nil) {         deviceannotationview = [[[mkpinannotationview alloc] initwithannotation:annotation reuseidentifier:@"deviceannotation"] autorelease];         deviceannotationview.animatesdrop = no;         deviceannotationview.pincolor = mkpinannotationcolorred;     }      return deviceannotationview; }  - (void)dealloc {     [super dealloc]; }  @end 

and here's code calling dashboardviewcontroller.m:

- (void)updatemapannotations:(nsarray *)devices {     (device *device in devices) {         [map addannotation:device];     } } 

and here's code calling updatemapannotations app delegate:

- (void)requestfinished:(asihttprequest *)request {     if (![request error]) {         nserror *jsonerror = nil;         nsdictionary *jsondictionary = [nsdictionary dictionarywithjsonstring:[request responsestring] error:&jsonerror];          if (!jsonerror || ([[jsondictionary objectforkey:@"success"] intvalue] == 1)) {             nsarray *jsondevicesarray = [jsondictionary objectforkey:@"devices"];             nsmutablearray *devicesarray = [[nsmutablearray alloc] initwithcapacity:[jsondevicesarray count]];              (nsdictionary *devicedictionary in jsondevicesarray) {                 [devicesarray addobject:[[[device alloc] initwithudid:[devicedictionary objectforkey:@"udid"] user:[devicedictionary objectforkey:@"user"] latitude:[nsnumber numberwithdouble:[[devicedictionary objectforkey:@"latitude"] doublevalue]] longitude:[nsnumber numberwithdouble:[[devicedictionary objectforkey:@"longitude"] doublevalue]]] autorelease]];             }              [dashboardviewcontroller updatemapannotations:devicesarray];         } else {             //  authorization failed         }     } } 

i make call server every 45 seconds, list of devices , locations json string deserialized nsarray containing device objects. pass array updatemapannotations loops , calls addannotation. whole process works, , guarantee objects being sent devicemapannotator of type device, mkuserlocation check returns prematurely , whole process stopped dead in water.

i appreciate if knows they're doing ios/objective-c, etc, can me out (that's pretty because apparently idiot).

just vent, must objective-c getting on $hit list fast.

i not seeing problem code either. however, instead of testing see if annotation mkuserlocation, instead not test directly , test whether annotation device, so:

- (mkannotationview *)mapview:(mkmapview *)mapview viewforannotation:(id <mkannotation>)annotation {     if ([annotation iskindofclass:[device class]]) {             mkpinannotationview *deviceannotationview = (mkpinannotationview *)[mapview dequeuereusableannotationviewwithidentifier:@"deviceannotation"];          if (deviceannotationview == nil) {              deviceannotationview = [[[mkpinannotationview alloc] initwithannotation:annotation reuseidentifier:@"deviceannotation"] autorelease];              deviceannotationview.animatesdrop = no;              deviceannotationview.pincolor = mkpinannotationcolorred;         }          return deviceannotationview;     } else {         nslog(@"annotation not device");          return nil;     } } 

this might not helpful suggestion since same thing, maybe doing different way yield different result when debugging , lead real problem.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -