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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:33:46+00:00 2026-05-24T22:33:46+00:00

I am new with MapKit and all its functionalities and therefore, stuck at trying

  • 0

I am new with MapKit and all its functionalities and therefore, stuck at trying to display a pin. I followed an online video tutorial on how to find user current location and drop a pin there. But when I typed the method for the pin, I do not get it at all. I would like to know where did I go wrong for this.

    - (void)viewDidLoad{
    [super viewDidLoad];

    self.title = @"Location";
    mapView.showsUserLocation = YES;
    self.locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    [locationManager startUpdatingLocation];
    [locationManager startUpdatingHeading];
}

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation{
    NSLog(@"Annotation view run");
    MKPinAnnotationView *pin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
    pin.animatesDrop = YES;
    return pin;
}

-(void) locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{

// once location is determined, center to that location.
location = newLocation.coordinate;
MKCoordinateRegion region;
region.center = location;

MKCoordinateSpan span;
span.latitudeDelta = 0.003;
span.longitudeDelta = 0.003;
region.span = span;

[mapView setRegion:region animated:FALSE];

}

Any advice of where I done wrong would be great!

  • 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-24T22:33:46+00:00Added an answer on May 24, 2026 at 10:33 pm

    As your method is never got invoked, you should do:

    - (void)mapView:(MKMapView *)aMapView regionDidChangeAnimated:(BOOL)animated {
        [aMapView removeAnnotation:[self point]];
        mkShape.coordinate = aMapView.centerCoordinate;
        [aMapView addAnnotation:mkShape];
    }
    

    And you should create your MKAnnotationView properly.
    You need create two properties in .h file first (for performance reason):

    MKPointAnnotation *mkShape;
    MKAnnotationView *annotationView;
    

    then use the code below to create your MKPointAnnotation

    - (void)createShape
    {
        if (!mkShape) {
            mkShape = [[MKPointAnnotation alloc] init];
            mkShape.title = nil;
            mkShape.subtitle = @"test description";
        }
    }
    
    - (id <MKAnnotation>)point
    {
        [self createShape];
    
        // Make sure to check if this is an MKPointAnnotation.  MKOverlays also
        // conform to MKAnnotation, so it isn't sufficient to just check to
        // conformance to MKAnnotation.
        if ([mkShape isKindOfClass:[MKPointAnnotation class]])
            return (id <MKAnnotation>)mkShape;
    
        return nil;
    }
    
    - (MKAnnotationView *)annotationView
    {
        if (!annotationView) {
            id <MKAnnotation> annotation = [self point];
            if (annotation) {
                MKPinAnnotationView *pin =
                [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil];
                pin.canShowCallout = YES;
                pin.animatesDrop = YES;
                pin.draggable = NO;
                annotationView = pin;
            }
        }
        return annotationView;
    }
    
    
    - (MKAnnotationView *)mapView:(MKMapView *)aMapView viewForAnnotation:(id <MKAnnotation>)annotation
    {
        if ([annotation isEqual:mkShape]) {
            return [self annotationView];
        }
        return nil;
    }
    

    At the end, don’t forget to release your properties.

    - (void)dealloc
    {
        [annotationView release];
        [mkShape release];
    
        [super dealloc];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to Linux programming in general. I am trying to communicate with a kernel
new to winform development. I am trying to add a 'login form' to my
New demo code: I am trying to get the captcha image from a AOL,
I'm starting a new app which uses the coreLocation and the mapkit frameworks. My
i'm NEW TO XCODE, working with mapkit and annotations, howver after building and running
In my application I am using mapkit. All the time I have more than
I am very new to MapKit so forgive me if I do not make
I am currently added a new view when a mapkit annotation is clicked: -(IBAction)showDetails:(id)sender{
New to Linq, trying to query an XDocument. I want elements where a certain
New to Ruby, and I'm trying to figure out what idiom to use to

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.