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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:57:39+00:00 2026-06-17T06:57:39+00:00

Within my app we have a screen with an MKMapView. This map shows pins

  • 0

Within my app we have a screen with an MKMapView.

This map shows pins for a bunch of Locations (location is a model defined within the app).

When running in the simulator this works fine. However, when running this on a device the pins seem to disappear and re-appear almost each time the map is panned. Even slight touches and movements can cause the map to show and hide pins.

The map isn’t particularly busy, even when showing one pin it will show and hide it.

Has anybody any idea why this might be happening? I’ve pasted my code below… It’s a Rubymotion app so the code is in Ruby.

– UPDATE –

I’ve added the Objective C equivalent to this Ruby code below. Apologies if there are a couple of typos or idiomatic errors, it’s been a while since I’ve written any OC.

– UPDATE 2 –

Watching the logger, I can see that mapView:viewForAnnotation is being called each time a map pin disappears/reappears.

Also each time mapView:regionDidChangeAnimated I can see that the Object IDs for the annotations are the same – so I don’t think they’re being removed (which they shouldn’t be)

# ====================
# = MKMapKitDelegate =
# ====================

# Don't react if the user has moved less than three meters
USER_MOVE_THRESHOLD = 3

# The user location has changed
def mapView(mapView, didUpdateUserLocation: newLocation)
  NSLog("mapView:didUpdateUserLocation")
  return unless userLocation
  coord = newLocation.coordinate
  newLocationAsCL = CLLocation.alloc.initWithCoordinate(coord, altitude: 1, horizontalAccuracy:1, verticalAccuracy: -1, timestamp: nil)    
  meters = newLocationAsCL.distanceFromLocation(@lastUserCLLocation)

  # If user has moved less than 3m, return
  if meters > 0 and meters < USER_MOVE_THRESHOLD
    log "Distance was less than #{USER_MOVE_THRESHOLD} meters (#{meters}) - returning ***"
    return
  end

  # If the coord is the same as the previous user location
  if userLocation.coordinate.latitude == coord.latitude && userLocation.coordinate.longitude == coord.longitude
    log "User hasn't moved - returning ***"
  else
    log 'User has moved'
  end

  log "Did update user location: #{coord.latitude},#{coord.longitude}"

  if coord.latitude.to_f == 0.0 and coord.longitude.to_f == 0.0
    log 'Invalid coordinate received - returning ***'
  else
    fetchLocationsFromAPI
  end
end

def mapView(mapView, regionDidChangeAnimated: animated)
  NSLog("mapView:regionDidChangeAnimated:#{animated}")
  # do nothing here yet...
end

# create map pins...
def mapView(mapView, viewForAnnotation: annotation)
  log "mapView:viewForAnnotation: #{annotation.inspect}"

  if annotation.is_a?(Location)
    # If there's already an annotation we can use, use it! Otherwise create a new one
    annotationView = mapView.dequeueReusableAnnotationViewWithIdentifier(annotation.class.to_s) || begin
      annotationView = MKPinAnnotationView.alloc.initWithAnnotation(annotation, reuseIdentifier: annotation.class.to_s)
      annotationView.enabled        = true
      annotationView.canShowCallout = true
      annotationView.animatesDrop   = false
      annotationView.pinColor = MKPinAnnotationColorRed

      rightButton = UIButton.buttonWithType(UIButtonTypeDetailDisclosure)
      rightButton.addTarget(self, action: 'showLocationScreen:', forControlEvents: UIControlEventTouchUpInside)
      annotationView.rightCalloutAccessoryView = rightButton      
      annotationView      
    end
    annotationView.annotation = annotation
    annotationView.rightCalloutAccessoryView.tag = @mapLocations.index(annotation)
    return annotationView
  end
end

def mapView(mapViewm, didAddAnnotationViews: views)
  NSLog("mapView:didAddAnnotationViews - #{views}")
  # do nothing here yet...
end

Objective C

#define kUserMoveThreshold 1

-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)newLocation
{
  NSLog(@"mapView:didUpdateUserLocation")
  if (!userLocation) {
    return;
  }
  CLLocationCoordinate2D coord = newLocation.coordinate;
  CLLocation newLocationAsCL = [[CLLocation alloc] initWithCoordinate: coord altitude: 1 horizontalAccuracy: 1 verticalAccuracy: -1 timestamp: NULL];
  CLLocationDistance meters = [newLocationAsCL distanceFromLocation: lastUserCLLocation];

  // If user has moved less than 3m, return
  if (meters > 0 && meters < kUserMoveThreshold){
    NSLog(@"Distance was less than %d meters (%d) - returning ***", kUserMoveThreshold, meters);
    return;
  }

  // If the coord is the same as the previous user location
  if (userLocation.coordinate.latitude == coord.latitude && userLocation.coordinate.longitude == coord.longitude){
    NSLog(@"User hasn't moved - returning ***");
    return;
  } else {
    NSLog(@"User has moved");  
  }
  NSLog(@"Did update user location: %f,%f", coord.latitude, coord.longitude);
  if (coord.latitude == 0.0 && coord.longitude == 0.0){
    NSLog(@"Invalid coordinate received - returning ***");
  } else {
    [self fetchLocationsFromAPI];
  }
}

-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
  NSLog(@"mapView:regionDidChangeAnimated: %s", animated ? @"TRUE" : @"FALSE");
}

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id < MKAnnotation >)annotation
{
  NSLog(@"mapView:viewForAnnotation %s", annotation.description);

  if ([annotation isKindOfClass: [Location class]]){
      // If there's already an annotation we can use, use it! Otherwise create a new one
    MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier: [annotation className]];
    if (!annotationView){
      annotationView = [[MKPinAnnotationView alloc] initWithAnnotation: annotation reuseIdentifier: [annotation className]];
      [annotationView setEnabled: YES];
      [annotationView setCanShowCallout: YES];
      [annotationView setAnimatesDrop: NO];
      [annotationView setPinColor: MKPinAnnotationColorRed];

      UIButton *rightButton = [UIButton buttonWithType: UIButtonTypeDetailDisclosure];
      [rightButton addTarget: self action: @selector(showLocationScreen:) forControlEvents: UIControlEventTouchUpInside];
      [annotationView setRightCalloutAccessoryView: rightButton];
    }

    [annotationView annotation: annotation];
    [[annotationView rightCalloutAccessoryView] setTag: [mapLocations indexOfObject: annotation]];
    return annotationView
  }
}

-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
  NSLog(@"mapView:didAddAnnotationViews %@", views)
}
  • 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-17T06:57:40+00:00Added an answer on June 17, 2026 at 6:57 am

    This was a bug with Rubymotion which seems to have been addressed in version 1.30

    = RubyMotion 1.30 =

    …

    • Fixed a bug where MapKit annotation pins would disappear, because certain
      Ruby objects (in this case, MKAnnotations) would use a Bignum value as the
      return value of the `hash’ method, which would not work properly when used
      within MapKit.

    …

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

Sidebar

Related Questions

We have an app selling content (ebooks) within the app and InApp Purchase. The
I have custom classes that I currently instantiate within App.xaml as resources. I want
I have other pages within my app preferences which are stored as separate files
I have a class library that has settings within an app.config. I know that
I have an app that finds other users within a 20 mile radius on
I have an app with a custom UITabBarController that contains five view controllers. Within
I have figured out how to add a custom calendar within my iPhone app,
I've created an online store within an android app in webview but have one
I have a folder within a site that is a seperate web app than
Within an asp.net MVC app, I'm trying to find rooms which have a guest/client,

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.