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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:25:02+00:00 2026-05-28T08:25:02+00:00

I need to display multiple annonation views in MKMapKit..I use this code.. – (void)viewDidLoad

  • 0

I need to display multiple annonation views in MKMapKit..I use this code..

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib

    [mapView setMapType:MKMapTypeStandard];
    [mapView setZoomEnabled:YES];
    [mapView setScrollEnabled:YES];
    DisplayMap *ann = [[DisplayMap alloc] init];
    //NSLog(@"xapp.arrplacename:%d",[xapp.arrplacename count]);
    for (i=0;i<=[arrplacename count]-1;i++)
    {

        MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
        //arrplacename contains the address of the locations
        NSString *straddress=[arrplacename objectAtIndex:i];
        NSString *strregion=@"";
        NSString *strs=[straddress stringByAppendingString: strregion];
        //  lbladdress.text=strs;
        //  NSString add=strs;
        // here you define the url setting your address
        NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",[strs stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding]];

        NSLog(@"US: %@",urlString);

        // then you get the response string here
        NSString *locationString = [[[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:urlString]] autorelease];
        NSLog(@"loaction strings%@",locationString);
        // now you can create an array splitting the response values using the ","
        //[listItems addObject:locationString];
        listItems = [locationString componentsSeparatedByString:@","];

        NSLog(@"A: %@",[xapp.listItems objectAtIndex:2]);

        // define latitude and longitude variables
        double latitude  = 0.0;
        double longitude = 0.0;

        NSString *strlatitude;
        NSString *strlongitude;

        strlatitude=[xapp.listItems objectAtIndex:2];
        strlongitude=[xapp.listItems objectAtIndex:3];

        float stringFloat = [strlatitude floatValue]; 
        float string1Float = [strlongitude floatValue]; 

        // if your array has inside the sctructure you aspect (4 values as described in my previous post) and the first value is like "200" (OK result)
        if([xapp.listItems count] >= 4 && [[xapp.listItems objectAtIndex:0] isEqualToString:@"200"]) 
        {
            // not sure if you need the accurancy parameter
            //accurancy = [[listItems objectAtIndex:1] intValue];

            // here you can get your values

            // latitude = [[listItems objectAtIndex:2] doubleValue];
            //longitude = [[listItems objectAtIndex:3] doubleValue];

            latitude = stringFloat;
            longitude = string1Float;

        }
        else {
            NSLog(@"Error on map");
        }
        region.center.latitude = latitude;
        region.center.longitude = longitude;
        NSLog(@"latitude:%g",region.center.latitude);
        //  region.center.latitude = 42.7157850;
        // region.center.longitude = 27.56470180;

        region.span.longitudeDelta = 0.01f;
        region.span.latitudeDelta = 0.01f;
        [mapView setRegion:region animated:YES];
        [mapView setDelegate:self];
        ann.title = [xapp.arrplacename objectAtIndex:i];
        ann.subtitle = [xapp.arrplacename objectAtIndex:i];
        ann.coordinate = region.center;
        [mapView addAnnotation:ann];

    }

}

I do have some problems in this code….all the coordnates are not added to the listitems array..I can see only the objects that are added atlast….

This is the delegates I add for displaying the annonation in my map..

- (CLLocationCoordinate2D) geoCodeUsingAddress:(NSString *)address{

    NSLog(@"ssssss");

    double latitude = 0, longitude = 0;
    NSString *esc_addr = [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSString *req = [NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?sensor=false&address=%@", esc_addr];
    NSString *result = [NSString stringWithContentsOfURL:[NSURL URLWithString:req] encoding:NSUTF8StringEncoding error:NULL];
    if (result) {
        NSScanner *scanner = [NSScanner scannerWithString:result];
        if ([scanner scanUpToString:@"\"lat\":" intoString:nil] && [scanner scanString:@"\"lat\":" intoString:nil]) {
            [scanner scanDouble:&latitude];
            if ([scanner scanUpToString:@"\"lng\":" intoString:nil] && [scanner scanString:@"\"lng\":" intoString:nil]) {
                [scanner scanDouble:&longitude];
            }
        }
    }
    CLLocationCoordinate2D center;
    center.latitude = latitude;
    center.longitude = longitude;

    return center;
}


-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:
(id <MKAnnotation>)annotation {

   MKPinAnnotationView *pinView = nil;
    NSLog(@"pinnview before release %d",[pinView retainCount]);

    if (pinView !=nil) {
        pinView =nil;
        [pinView release];
    }
    NSLog(@"pinnview after release %d",[pinView retainCount]);

    // if it's the user location, just return nil.
    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;

    if(annotation != mapView.userLocation)
    {

        static NSString *defaultPinID = @"your-pin";

        pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];

        if ( counting < [mapView.annotations count])
        {
            counting++;

            pinView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];


           /* for(DisplayMap* a in mapView.annotations)
            {
                if (annotation == a){
                    pinView.image =
                    [UIImage imageWithContentsOfFile:
                     [[NSBundle mainBundle] pathForResource:a.image ofType:nil]];   
                }
            }*/
            pinView.centerOffset= CGPointMake(0,-10);
            pinView.canShowCallout = YES;


        }

    }

   // return pinView;


}

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
    NSLog(@"enter");
    [mapView selectAnnotation:[[mapView annotations] lastObject] animated:YES];
}

Delegates are called only once eventhough I’m using [mapView addAnnotation:ann]; inside the for loop…And it shows pin only for the last item tatz added in the array…How can I overcome this????

  • 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-28T08:25:03+00:00Added an answer on May 28, 2026 at 8:25 am

    You are allocating and initializing ‘ann’ only once before the for loop starts, and you are altering the same and adding it again and again into Map. Thats why you are getting only one annotation.

    Move this line inside for loop and try,

    DisplayMap *ann = [[DisplayMap alloc] init];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to display some text on multiple views loaded on a UIScrollView .
I need to display additional information, like a tooltip, but it's a lot of
I need to display multiple markers on a map, each with their own infowindow.
I need to display multiple pieces of data in a combobox, but I can't
I have a master-detail page, in which I use GridView to display multiple rows
I need to display a detailed view controller with multiple labels when a row
I need to display multiple lines of text in an Alert Dialog. If I
I need some help finding a jQuery solution to display multiple images in a
I need to display multiple images for a a car from a separate linked
I need to display multiple lines of messages, rather than just one paragraph, in

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.