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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:03:51+00:00 2026-06-04T00:03:51+00:00

I’m confused on how this works. I’m creating a CLGeocoder to drop a pin

  • 0

I’m confused on how this works. I’m creating a CLGeocoder to drop a pin based on a string value. I have this:

- (void)placeMarkFromString:(NSString *)address {
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder geocodeAddressString:address completionHandler:^(NSArray *placemarks, NSError *error) {
        [placemarks enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
            NSLog(@"%@", [obj description]);
        }];

        // Check for returned placemarks
        if (placemarks && [placemarks count] > 0) {
            CLPlacemark *topResult = [placemarks objectAtIndex:0];

            // Create an MKPlacemark and add it to the mapView
            MKPlacemark *place = [[MKPlacemark alloc] initWithPlacemark:topResult];
            AddressAnnotation *anAddress = [[AddressAnnotation alloc] init];
            anAddress.address = place.subThoroughfare;
            anAddress.street = place.thoroughfare;
            anAddress.city = place.locality;
            anAddress.state = place.administrativeArea;
            anAddress.zip = place.postalCode;
            anAddress.name = place.name;

            //[self.mapView addAnnotation:place];
            [self.mapView addAnnotation:anAddress];
            self.currentPlacemark = place;

            // Center map on that region
            MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(topResult.location.coordinate, 2000, 2000);
            MKCoordinateRegion adjustedRegion = [_mapView regionThatFits:region];
            [_mapView setRegion:adjustedRegion animated:YES];
        }
        else {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Results Found" message:@"" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];
            [alert show];
        }
        if (error) {
            NSLog(@"Error: %@", [error localizedDescription]);
        }
    }];
}

So originally, I added my MKPlacemark to the map and it shows the red pin. It does not animate however. I basically want the ability to drop any of the 3 MKPinAnnotationView colors, have a callout and the title/subtitle to be the name and address of the place, similar to how google maps does it. But I was not getting any animation.

So I thought that maybe I needed to create my own object that conforms to the MKAnnotation class. So I did that, but when I try to add it to the location, I do not see its annotationView in the viewForAnnotation delegate method. That method is here:

- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id<MKAnnotation>)annotation {
    static NSString *placeMarkIdentifier = @"SimplePinIdentifier";
    if ([annotation isKindOfClass:[AddressAnnotation class]]) {
        MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[theMapView dequeueReusableAnnotationViewWithIdentifier:placeMarkIdentifier];
        if (annotationView == nil) {
            annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:placeMarkIdentifier];
        }
        else {
            annotationView.annotation = annotation;
        }
        annotationView.enabled = YES;
        annotationView.animatesDrop = YES;
        annotationView.draggable = YES;
        annotationView.pinColor = MKPinAnnotationColorPurple;
        annotationView.canShowCallout = YES;


        // Create a button for the annotation
//        UIButton *rightArrowButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
//        annotationView.rightCalloutAccessoryView = rightArrowButton;
//        [self performSelector:@selector(openCallout:) withObject:annotation afterDelay:0.5];
        return annotationView;
    }
    return nil;

}

So I guess my questions are, do I need to create my own object to do this, am I on the right track, what am I doing wrong, and why is it that in one case, I am adding a MKPlacemark object, and then if I do it the way other way, I add a object, but not necessarily a subclass of MKPlacemark. Thanks!

  • 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-04T00:03:53+00:00Added an answer on June 4, 2026 at 12:03 am

    First, the reason you’re probably not seeing the annotation view when you use a custom annotation object (ie. AddressAnnotation) is that its coordinate is not being set (and so it’s appearing at 0,0).

    In the placeMarkFromString method, the code sets a lot of properties of the AddressAnnotation but not the coordinate and so the annotation is not appearing where expected.

    If you set the coordinate, it will appear where expected and with the animation.

    Regarding the other question as to why you see no animation when using an MKPlacemark:

    By default, the map view will create an MKPinAnnotationView with a red pin but with animatesDrop set to NO.

    So in viewForAnnotation, you have to explicitly do it for MKPlacemark just like you are for AddressAnnotation.

    If all your annotations will be using MKPinAnnotationView, instead of checking for each different class of annotation you will be creating, you can flip the condition around by returning nil at the top of the method when the annotation class is MKUserLocation and then run the rest of the code without any class-checking (ie. returning MKPinAnnotationView with animatesDrop set to YES in all other cases).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.