Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3942028
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:36:49+00:00 2026-05-20T00:36:49+00:00

I have a custom class called Device which implements the MKAnnotation protocol. In the

  • 0

I have a custom class called Device which implements the MKAnnotation protocol. In the examples I’m following (MapKit and Core Location on the iPad from O’Reilly Media), they say to check if the annotation I want to add is an MKUserLocation class and return nil if it is. I fully understand what that does, but the problem is that my Device class is always identified as MKUserLocation so it always returns nil so I never get any annotations added to the map. I’ve gone over the code again and again and again. I’ve the O’Reilly code samples as well and I can’t see where I’m going off. It’s really frustrating.

Here’s my 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 my DeviceMapAnnotator.m:

@implementation DeviceMapAnnotator

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    if ([annotation isKindOfClass:[MKUserLocation class]]) {
        NSLog(@"annotation is an 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 the code calling it from my DashboardViewController.m:

- (void)updateMapAnnotations:(NSArray *)devices {
    for (Device *device in devices) {
        [map addAnnotation:device];
    }
}

And here’s the code calling updateMapAnnotations from my 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]];

            for (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 basically make a call to the server every 45 seconds, get a list of devices and their locations as a JSON string which is then deserialized into an NSArray containing Device objects. I then pass the array to updateMapAnnotations which then loops it and calls addAnnotation. The whole process works, and I guarantee that the objects being sent to DeviceMapAnnotator are of type Device, however the MKUserLocation check always returns prematurely and the whole process is just stopped dead in the water.

I would really appreciate it if someone who knows what they’re doing with iOS/Objective-C, etc, can help me out (that’s pretty much everyone because I apparently am an idiot).

Just to vent, I must say that Objective-C is getting on my $hit list really fast.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T00:36:50+00:00Added an answer on May 20, 2026 at 12:36 am

    Okay, I got it to work, although I don’t know exactly what the solution was. In the end I scrapped everything and rewrote it from scratch in a new file and it worked at that point. I also realized that I was not sending back the latitude and logitude in the JSON, however that still wasn’t the problem because they would be initialized as 0.0 anyway. In the end I have no idea what really fixed it, but it works, so I’ll take it.

    Sorry to waste your guys’ time. 🙁

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom class called Rows that implements IEnumerable<Row> . I often use
Based on this article , I've written a custom class which implements the Watin.Core.interfaces.IFindByDefaultFactory,
I have a custom class that implements that IComparable. This class is stored in
I have a custom class that implements ICollection , and this class is readonly,
I currently have a custom session handler class which simply builds on php's session
I have a custom attribute which can be assigned to a class, [FooAttribute] .
I have a custom class called NoteView that extends FrameLayout . Previously, I had
If I have a custom class called Tires: #import <Foundation/Foundation.h> @interface Tires : NSObject
I have an NSInteger property of a custom class called 'estimatedTime', now, in my
I have a custom class loader so that a desktop application can dynamically start

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.