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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:03:55+00:00 2026-05-29T22:03:55+00:00

Why will my code not remove the map annotation? I hit the button and

  • 0

Why will my code not remove the map annotation?

I hit the button and it gets the users location and then pins it to the map. The problem is that when the button is hit a second, third, ……. time It just keeps adding pins instead of removing the first pin (simulating replacing the pin).

I have tried adding another button (clear pins) and following this thread :http://stackoverflow.com/questions/3027392/how-to-delete-all-annotations-on-a-mkmapview but the app just crashes with no debug info.

But in theory my code should work. So what am I not understanding?

- (IBAction)getLocation:(id)sender {
    MapAnnotation *ann1 =[[[MapAnnotation alloc] init]autorelease]; 

    // remove annotation
    [mapView removeAnnotation:ann1];


    locationManager = [[CLLocationManager alloc] init];
    locationManager.distanceFilter=kCLDistanceFilterNone;
    locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
    [locationManager startUpdatingLocation];

    [mapView setMapType:MKMapTypeStandard];
    [mapView setZoomEnabled:YES];
    [mapView setScrollEnabled:YES];
    MKCoordinateRegion region = {{0.0,0.0},{0.0,0.0}};
    region.center.latitude = locationManager.location.coordinate.latitude;
    region.center.longitude = locationManager.location.coordinate.longitude;
    region.span.longitudeDelta = 0.005f;
    region.span.latitudeDelta = 0.005f;
    [mapView setRegion:region animated:YES];
    [mapView setDelegate:sender];

    MKCoordinateRegion location1;
    location1.center.latitude =locationManager.location.coordinate.latitude;
    location1.center.longitude= locationManager.location.coordinate.longitude;
    location1.span.longitudeDelta=0.1;
    location1.span.latitudeDelta =0.1;


    // Add Annotation
    //MapAnnotation *ann1 =[[MapAnnotation alloc] init];
    ann1.title=@"You Parked Here";
    ann1.subtitle=@"";
    ann1.coordinate= location1.center;
    [mapView addAnnotation:ann1];

}
  • 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-29T22:03:56+00:00Added an answer on May 29, 2026 at 10:03 pm

    You’re removing an annotation that you just created, and which hasn’t been added to the map:

    MapAnnotation *ann1 =[[[MapAnnotation alloc] init]autorelease];
    // remove annotation
    [mapView removeAnnotation:ann1];
    

    You can either locate the annotation on the map, and then remove it, or you can take a heavy-handed approach and simply remove all the annotations in one swoop. Since I don’t know the UI interaction, I can’t really outline how to locate the annotation for you. However, here’s how to remove all:

    NSMutableArray *annotations = [NSMutableArray array];
    for (id annotation in [mapView annotations])
    {
      [annotations addObject:annotation];
    }
    [mapView removeAnnotations:annotations];
    

    HTH.

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

Sidebar

Related Questions

I am unsure why this code will not work. When I click a button
I have some code that compiles and runs on MSVC++ but will not compile
I now understand that the following code will not work because I'm assigning window.onload
I am having a problem with the <text> tag. The following code will not
The following code will not run correctly in IE7 with the latest service packs
sorry but I do not have the actual code with me, but I will
I have the following code, which will not work. The javascript gives no errors
I have a basic ajax application, which will not work, instead the php code
I'm trying to remove a dynamic form field by click a button. It will
I have a problem that I have not managed to solve. I developed a

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.