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

The Archive Base Latest Questions

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

I have an NSArray of custom objects which are called Proximity . I add

  • 0

I have an NSArray of custom objects which are called Proximity. I add these to the map by creating a new ProximityAnnotation like the following:

// Add the annotations to the map
if (self.proximityItems) {
    for (Proximity *proximity in self.proximityItems) {

        // Create a pin
        ProximityAnnotation *proximityAnnotation = [[ProximityAnnotation alloc] init];
        proximityAnnotation.coordinate = CLLocationCoordinate2DMake([proximity.latitude doubleValue], [proximity.longitude doubleValue]);
        proximityAnnotation.title = proximity.title;
        proximityAnnotation.subtitle = NSLocalizedString(@"Drag to change location", nil);
        [self.map addAnnotation:proximityAnnotation];

    }//end

    // Create the map rect
    MapUtility *util = [[MapUtility alloc] init];
    [util zoomMapViewToFitAnnotations:self.map animated:YES];
}//end

This works great.

Now, when I drag an annotation, I would like to update the corresponding ProximityAnnotation object that is contained in my proximityItems array. I am trying to do this by doing the following:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)annotationView didChangeDragState:(MKAnnotationViewDragState)newState fromOldState:(MKAnnotationViewDragState)oldState {

    // Get the coordiante
    if ([annotationView.annotation isKindOfClass:[ProximityAnnotation class]] && newState == MKAnnotationViewDragStateEnding) {
        ProximityAnnotation *annotation = (ProximityAnnotation *)annotationView.annotation;
        CLLocationCoordinate2D coordinate = annotation.coordinate;

        // Find the annotation that matches
        for (Proximity *proximity in self.proximityItems) {
            NSLog(@"%f == %f && %f == %f && %@ == %@", [proximity.latitude doubleValue], coordinate.latitude, [proximity.longitude doubleValue], coordinate.longitude, annotation.title, proximity.title);
            if ([proximity.latitude doubleValue] == coordinate.latitude && [proximity.longitude doubleValue] == coordinate.longitude && [annotation.title isEqualToString:proximity.title]) {

                // Update the proximity item
                proximity.longitude = [NSNumber numberWithDouble:coordinate.longitude];
                proximity.latitude = [NSNumber numberWithDouble:coordinate.latitude];

                break;
            }
        }//end

    }//end

}//end

Unfortunately, this doesn’t seem to get a match even though there is only 1 annotation on the map. Here is what was logged from my NSLog:

37.627946 == 37.622267 && -122.431599 == -122.435596 && Testlocation == Testlocation

Strangely, the double values seem to get a bit off, but I am not sure why.

Is there a better way to match the annotation to the object that I have in my array, so that I can updated that original object?

  • 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-13T05:01:29+00:00Added an answer on June 13, 2026 at 5:01 am

    The coordinate values are most likely “off” because the annotation has been dragged to a new location.

    Even if the values were equal, I don’t recommend comparing floating-point numbers as a test for object equality.

    Instead, I suggest these options:

    • Add a reference to the source Proximity object in the ProximityAnnotation class and set it when creating the annotation (eg. proximityAnnotation.sourceProximity = proximity;). Then to update the original Proximity object, you can get a reference to it directly from the annotation itself.
    • Eliminate the ProximityAnnotation class and make the Proximity class itself implement the MKAnnotation protocol in which case an update might not even be necessary.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have an NSArray which contains custom objects, the objects have an NSString property,
So I have an NSArray with custom objects called Church. And in each church
I have an NSArray of NSDictionary objects which I would like to be able
I have an array of custom objects. The objects includes a dictionary. Something like
I have an NSArray formed with objects of a custom class. The class has
I have several custom objects in an NSArray, I need to search through all
I have an NSArray of custom objects that all have a @property name of
I have a NSMutableArray containing custom objects of type Episode. Each of these objects
I have a core data application which displays a list of custom objects, each
I have an NSDictionary which contains (my custom) GTPerson objects. GTPerson has an NSMutableSet

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.