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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:01:28+00:00 2026-06-12T09:01:28+00:00

I have some questinos regarding iOS6 mapkit. I tried to create a simple application

  • 0

I have some questinos regarding iOS6 mapkit. I tried to create a simple application that shows my current location and adds custom annotations to my MapView control. This is my code:

@interface MapViewAnnotation : NSObject<MKAnnotation>{}

@property (nonatomic, copy) NSString *title;
@property (nonatomic, readonly) CLLocationCoordinate2D cordinate;

- (id) initWithTitle:(NSString *) t coordinate:(CLLocationCoordinate2D) c;

@end

And the implementation:

#import "MapViewAnnotation.h"
@implementation MapViewAnnotation
@synthesize title;
@synthesize coordinate;
- (id) initWithTitle:(NSString *) t coordinate:(CLLocationCoordinate2D) c{
    self = [super init];
    self.title = t;
    self.coordinate = c;
    return self;
}
@end

And this is UIViewController:

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
@interface ViewController : UIViewController <CLLocationManagerDelegate,MKMapViewDelegate>{}

@property (nonatomic, strong) IBOutlet MKMapView *mapView;
@property (nonatomic, strong) CLLocationManager *locationManager;
@end

And the .main file:

#import "ViewController.h"
#import "MapViewAnnotation.h"
@interface ViewController () @end
@implementation ViewController
@synthesize mapView, locationManager;
- (void)viewDidLoad{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    self.mapView.delegate = self;

    self.locationManager = [[CLLocationManager alloc] init];
    [locationManager setDelegate:self];

    [locationManager setDistanceFilter:kCLDistanceFilterNone];
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];

    [self.mapView setShowsUserLocation:YES];

    CLLocationCoordinate2D location;
    location.latitude = 37.78608;
    location.longitude = -122.405398;

    MapViewAnnotation *mapAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Store location" coordinate:location];
    [self.mapView addAnnotation:mapAnnotation];
}
-(void) mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views{
    MKAnnotationView *annotationView = [views objectAtIndex:0];
    id<MKAnnotation> mp = [annotationView annotation];

    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate], 250, 250);
    [self.mapView setRegion:region animated:YES];
}
@end

It displays my current location successfully, but when I use this line in viewDidLoad:

MapViewAnnotation *mapAnnotation = [[MapViewAnnotation alloc] initWithTitle:@"Store location" coordinate:location];

I get this exception:

MapKitDemo[3426:c07] -[MapViewAnnotation setCoordinate:]: unrecognized selector sent to instance 0x8551ae0
2012-10-03 16:19:23.070 MapKitDemo[3426:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MapViewAnnotation setCoordinate:]: unrecognized selector sent to instance 0x8551ae0'

What am I doing wrong?

  • 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-06-12T09:01:29+00:00Added an answer on June 12, 2026 at 9:01 am

    You are using the property self.coordinate in the -initWithTitle:coordinate: method of your subclass, this means that the coordinate is being set using the property as opposed to the iVar, since this property is set to readonly, you are getting this error and probably crash…

    You must access the iVar directly like so:

    #import "MapViewAnnotation.h"
    @implementation MapViewAnnotation
    
    @synthesize title = _title, coordinate = _coordinate    
    
    - (id) initWithTitle:(NSString *) t coordinate:(CLLocationCoordinate2D) c{
        self = [super init];
        if(self){
            _title = t;
            _coordinate = c;
            // self.coordinate = c /* !This is readonly ! */
        }
        return self;
    }
    @end
    

    Notice I also changed the @synthesize (which isn’t required anymore – this is done automatically as of Xcode 4.5 I believe? Maybe an earlier version). Also note that I did a condition in your init, you should do this it will make sure you don’t try to et properties/iVars on nil in the case that [super init] failed to initialise your object.

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

Sidebar

Related Questions

I have some questions regarding the following css that I found: html, body {
I have an other active question HERE regarding some hopeless memory issues that possibly
I have some questions regarding data base design for simple CMS. Every Page in
I am writing a small application in c++ and I have some questions regarding
I have some questions regarding the MATLAB Search Path: The current directory is on
I have some questions regarding MVC that I would like to clarify. At our
I've read some documentation on how Adaboost works but have some questions regarding it.
There have been some similar questions asked regarding Grid views, but none have been
I have couple questions regarding some C++ rules. Why am I able to call
I have some question over here regarding the java garbage collector. First let me

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.