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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:09:33+00:00 2026-05-29T08:09:33+00:00

I have a MKMapView (obviously), that shows housing locations around the user. I have

  • 0

I have a MKMapView (obviously), that shows housing locations around the user.

I have a Radius tool that when a selection is made, the annotations should add/remove based on distance around the user.

I have it add/removing fine but for some reason the annotations won’t show up until I zoom in or out.

This is the method that adds/removes the annotations based on distance. I have tried two different variations of the method.

  1. Adds the new annotations to an array, then adds to the map by [mapView addAnnotations:NSArray].

  2. Add the annotations as it finds them using [mapView addAnnotation:MKMapAnnotation];


1.

- (void)updateBasedDistance:(NSNumber *)distance {

    //Setup increment for HUD animation loading
    float hudIncrement = ( 1.0f / [[[[self appDelegate] rssParser]rssItems] count]);

    //Remove all the current annotations from the map
    [self._mapView removeAnnotations:self._mapView.annotations];

    //Hold all the new annotations to add to map
    NSMutableArray *tempAnnotations;

    /* 
     I have an array that holds all the annotations on the map becuase 
     a lot of filtering/searching happens. So for memory reasons it is
     more efficient to load annoations once then add/remove as needed.
    */
    for (int i = 0; i < [annotations count]; i++) {

        //Current annotations location
        CLLocation *tempLoc = [[CLLocation alloc] initWithLatitude:[[annotations objectAtIndex:i] coordinate].latitude longitude:[[annotations objectAtIndex:i] coordinate].longitude];

        //Distance of current annotaiton from user location converted to miles
        CLLocationDistance miles = [self._mapView.userLocation.location distanceFromLocation:tempLoc] * 0.000621371192;

        //If distance is less than user selection, add it to the map. 
        if (miles <= [distance floatValue]){
            if (tempAnnotations == nil)
                tempAnnotations = [[NSMutableArray alloc] init];
            [tempAnnotations addObject:[annotations objectAtIndex:i]];
        }

        //For some reason, even with ARC, helps a little with memory consumption
        tempLoc = nil;

        //Update a progress HUD I use. 
        HUD.progress += hudIncrement;
    }

    //Add the new annotaitons to the map
    if (tempAnnotations != nil)
        [self._mapView addAnnotations:tempAnnotations];
}

2.

- (void)updateBasedDistance:(NSNumber *)distance {

    //Setup increment for HUD animation loading
    float hudIncrement = ( 1.0f / [[[[self appDelegate] rssParser]rssItems] count]);

    //Remove all the current annotations from the map
    [self._mapView removeAnnotations:self._mapView.annotations];

    /* 
     I have an array that holds all the annotations on the map becuase 
     a lot of filtering/searching happens. So for memory reasons it is
     more efficient to load annoations once then add/remove as needed.
    */
    for (int i = 0; i < [annotations count]; i++) {

        //Current annotations location
        CLLocation *tempLoc = [[CLLocation alloc] initWithLatitude:[[annotations objectAtIndex:i] coordinate].latitude longitude:[[annotations objectAtIndex:i] coordinate].longitude];

        //Distance of current annotaiton from user location converted to miles
        CLLocationDistance miles = [self._mapView.userLocation.location distanceFromLocation:tempLoc] * 0.000621371192;

        //If distance is less than user selection, add it to the map. 
        if (miles <= [distance floatValue])
            [self._mapView addAnnotation:[annotations objectAtIndex:i]];

        //For some reason, even with ARC, helps a little with memory consumption
        tempLoc = nil;

        //Update a progress HUD I use. 
        HUD.progress += hudIncrement;
    }
}

I have also attempted at the end of the above method:

[self._mapView setNeedsDisplay];
[self._mapView setNeedsLayout];

Also, to force a refresh (saw somewhere it might work):

self._mapView.showsUserLocation = NO;
self._mapView.showsUserLocation = YES;

Any help would be very much appreciated and as always, thank you for taking the time to read.

  • 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-29T08:09:34+00:00Added an answer on May 29, 2026 at 8:09 am

    I’m going to guess that updateBasedDistance: gets called from a background thread. Check with NSLog(@"Am I in the UI thread? %d", [NSThread isMainThread]);. If it’s 0, then you should move the removeAnnotations: and addAnnotation: to a performSelectorOnMainThread: invocation, or with GCD blocks on the main thread.

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

Sidebar

Related Questions

As well as my question Removing MKMapView Annotations causes leaks. I have discovered that
I have an MKMapView which allows the user to scroll the map around. Later,
I have a MKMapView that has a pin than when pressed shows the annotation's
I have a MKMapView. I need to add a circle as a radius around
I have a MKMapView that has a number of annotations. Selecting the pin displays
I have an MKMapView with an MKUserTrackingBarButtonItem . The user's current location should only
I have a MKMapView with some custom annotations that don't look that great when
I have an MKMapView that's supposed to track the user's location using a custom
I have a MKMapView annotation object that has a right callout accessory detail disclosure
I have a MKMapView & I use it to display user's current location. It

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.