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

  • Home
  • SEARCH
  • 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 7945345
In Process

The Archive Base Latest Questions

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

I have a mutablearray that is populated from sqlite db in ios. I have

  • 0

I have a mutablearray that is populated from sqlite db in ios. I have gotten the annotations to load and view properly. My question is how can I write a loop that will add annotations with the size of the array. I have tried the following code and get and display the last entry in the array

NSMutableArray *annotations=[[NSMutableArray alloc] init];
CLLocationCoordinate2D theCoordinate5;
MyAnnotation* myAnnotation5=[[MyAnnotation alloc] init];
for (int i = 0; i < _getDBInfo.count; i++) {

    dbInfo *entity = [_getDBInfo objectAtIndex:i];

    NSNumber *numlat=[[NSNumber alloc] initWithDouble:[entity.Latitude doubleValue]];
    NSNumber *numlon=[[NSNumber alloc] initWithDouble:[entity.Longitude doubleValue]];
    NSLog(@"%d",[_getDBInfo count]);
    la=[numlat doubleValue];
    lo=[numlon doubleValue];
    theCoordinate5.latitude=la;
    theCoordinate5.longitude=lo;

    myAnnotation5.coordinate=theCoordinate5;
    myAnnotation5.title=[NSString stringWithFormat:@"%@"entity.EntityNo];
    myAnnotation5.subtitle=[NSString stringWithFormat:@"%@",entity.EntityName]; 
    [mapView addAnnotation:myAnnotation5];
    [annotations addObject:myAnnotation5];
}

I guess my question is how can I create and add to my view annotation objects based on the count in my array?

Any help is much appreciated.

I am new to iOS as well as programming so please be gentle.

  • 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:49:59+00:00Added an answer on June 4, 2026 at 12:49 am

    You only have one myAnnotation5 object. When you set its coordinate, title, etc., you are setting it for that instance, which you happen to have added to annotations multiple times. Hence every entry in annotations will have the last set of properties you set – since every entry in annotations is actually the same object.

    To remedy this, you need to create your myAnnotation5 object anew each iteration of the loop, i.e.

    for (int i = 0; i < _getDBInfo.count; i++) {
        MyAnnotation* myAnnotation5=[[MyAnnotation alloc] init];
        ...
        myAnnotation5.coordinate=theCoordinate5;
        myAnnotation5.title=[NSString stringWithFormat:@"%@", entity.EntityNo];
        myAnnotation5.subtitle=[NSString stringWithFormat:@"%@", entity.EntityName];
        ...
        [mapView addAnnotation:myAnnotation5];
    }
    

    Two asides:

    1. I hope you are building with ARC, otherwise you are leaking memory left and right.
    2. Since MKMapView has an -annotations property, there is likely little reason for you to keep your own annotations array – just keep a reference to mapView.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a UITableView populated with a mutablearray that is read from NSUserDefaults. I
I have a one-time need to create a file from an iOS mutable array.
I have a UITableView that was created from data coming from a mutable array.
I have a UITableView that is populated with cells of a variable height. I
I have a table view that displays a list that I want the user
I accessed the Data from sqlite file as NSMutableArray[model_Array] in which I have duplicates
I have a view controller with table view that contains 8 cells(sections).I have created
I have multiple mock databases within my iOS application that I am making. I
I have a mutable array that is retained and storing several objects. At some
Have a SomeLib.pro file that contains: CONFIG += debug TEMPLATE = lib TARGET =

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.