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 6014481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:41:54+00:00 2026-05-23T02:41:54+00:00

I am working on a simple GPS-like app. I created a custom object which

  • 0

I am working on a simple GPS-like app. I created a custom object which extends MKAnnotation which also works fine. I can place it etc, but if I put this piece of code [mpm setCoordinate:loc]; in my code, the app opens and freezes while showing the basic gray-grid (not showing any downloaded map and non of my buttons work either then)

Here is my header:

@interface FirstViewController : UIViewController <MKMapViewDelegate>
{
    IBOutlet MKMapView *mapView;
    MyPlaceMark *mpm;
}
-(void)locationUpdate:(CLLocation *)location;
-(void)locationError:(NSError *)error;
@end

And here is the piece of code where I try to update things:

-(void)locationUpdate:(CLLocation *)location
{
    CLLocationCoordinate2D loc = [location coordinate];
    [mpm setCoordinate:loc]; // This line messes it up.
    [mapView setCenterCoordinate:loc];
    if([mapView showsUserLocation] == NO)
         [mapView setShowsUserLocation:YES]; // This does not show my position either?
}

If I comment that line out, the app works fine. I need to update the annotation as it will be my marker for showing the users current location. PS: Without that line, it does center my view – so location is a valid/set variable.

My viewDidLoad looks like this:

- (void)viewDidLoad {
    mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
    //mapView.showsUserLocation = YES;
    [mapView setShowsUserLocation:YES];
    mapView.mapType = MKMapTypeStandard;
    mapView.delegate = self;
    CLLocationCoordinate2D location;
    MKCoordinateRegion region;
    location.latitude = -33.8;
    location.longitude = 18.6;
    MKCoordinateSpan span;
    span.latitudeDelta = 0.01;
    span.longitudeDelta = 0.01;
    region.span = span;
    region.center = location;
    [mapView setRegion:region animated:TRUE];
    [mapView regionThatFits:region];
    mpm = [[MyPlaceMark alloc] initWithCoordinate:location]; // Creating mpm
    [mapView addAnnotation:mpm]; // Adding mpm
    [self.view addSubview:mapView];
    [super viewDidLoad];
}

Should I re-add mpm after I changed it’s location? Or would it just jump to its new location on the map?

So to recap the question: How can I update the custom MKAnnotation’s location on my mapview?

Thank you for your time!

EDIT: I think the main reason for the crash is the fact that I do not create a setCoordinate method/function in my custom MKAnnotation. How would I override that but keep it same as original?

The error in log-console:

2011-06-09 14:42:40.377 AeroNav[3706:707] -[MyPlaceMark setCoordinate:]: unrecognized selector sent to instance 0x19e0e0
2011-06-09 14:42:40.493 AeroNav[3706:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MyPlaceMark setCoordinate:]: unrecognized selector sent to instance 0x19e0e0'
...
terminate called after throwing an instance of 'NSException'
  • 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-23T02:41:55+00:00Added an answer on May 23, 2026 at 2:41 am

    [mapView setShowsUserLocation:YES] doesn’t update the region that the map shows. You will have to implement the delegate methods didUpdateUserLocation: and call the setRegion:animated: there to move the region to user’s location. Until this is called for the first time, the userLocation property of MKMapView is not set.

    As for the MKAnnotation thing, MKAnnotation is a protocol. It doesn’t have a default implementation. You will have to provide for all the methods and properties that you’ve agreed to conform to. So declare a property pretty similar to the one in the MKAnnotation protocol.

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

Sidebar

Related Questions

I'm working on simple videochat app with Adobe FMS 4.5. Everything works fine except
i am working on a simple web app which has a user model and
hi iam currently working in simple amimation app in which i implement following code
Can anyone supply me with simple working examples which illustrate the use of pragmas
I'm working on a simple multiplayer game in which 2-4 players are placed at
I am working on a simple CAD program which uses OpenGL to handle on-screen
I am working on simple form to validate fields like this one. public class
I am working on a simple web app using jquery mobile. I am attempting
I am working in simple application in which I need to post data to
I am working on simple application which creates google calendar (under it's own account).

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.