3

I have filled a NSMutablearray with Objects from my XML praser. I now what to use that to populate for my Map Annotations. I have this Array working for my Table which brings the objects into the cell, but I want to use the same NSMutablearray for my map.

//currentBranch is filled with my Objects
Mapdets *currentBranch = [[xmlParser branch]];



[mapview setMapType:MKMapTypeStandard];
[mapview setZoomEnabled:YES];
[mapview setScrollEnabled:YES];

MKCoordinateRegion region = {{0.0, 0.0}, {0.0,0.0 }};
region.center.latitude = -33.86434888;
region.center.longitude = 151.2090236;
region.span.longitudeDelta = 0.10f;
region.span.latitudeDelta = 0.10f;
[mapview setRegion:region animated:YES];




 //Annotation code will go here. Need help with that.

Ok So this is where i'm at. I have that array filled with objects that is filled with Title, subtile, Latitude, Longitude, i want to basically xpolde that array and use the elements.

Thanks for the help.

My array is filled as such if i run NSLog(@"%@", currentBranch);

2013-02-28 07:53:53.537 SAMPLE[13642:207] (
    "<Mapdets: 0x754d3b0>",
    "<Mapdets: 0x754d5c0>",
    "<Mapdets: 0x754d710>"
)

And in my XMLpraser file i fill it like this.

- (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName 
{
    if (isStatues) 
    {
        if ([elementname isEqualToString:@"title"]) 
        {
            currentBranch.title = currentNodeContent;


        }
        if ([elementname isEqualToString:@"street_address"]) 
        {
            currentBranch.subtitle = currentNodeContent;
        }
        if ([elementname isEqualToString:@"lng"]) 
        {
            currentBranch.lng = currentNodeContent;
        }
        if ([elementname isEqualToString:@"lat"]) 
        {
            currentBranch.lat = currentNodeContent;
        }
    }
    if ([elementname isEqualToString:@"branch"]) 
    {
        [self.branch addObject:currentBranch];
        currentBranch = nil;
        currentNodeContent = nil;

This is all working, I just want to now use this NSMutablearray in another class for my map.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Cliffordwh
  • 1,422
  • 1
  • 10
  • 18
  • may be this can be a help : http://stackoverflow.com/questions/8711086/adding-multiple-annotations-to-iphone-mapview-is-slow – rptwsthi Feb 28 '13 at 05:48
  • can you show us your array content???? You must be having dictionaries in that array. – Baby Groot Feb 28 '13 at 05:49
  • I added some revised code to how i fill the array. thanks – Cliffordwh Feb 28 '13 at 06:03
  • does these values in ur NSLog looks like ur values???? i guess you first need to first parse your xml properly. – Baby Groot Feb 28 '13 at 06:16
  • @Smriti if i do this, i can see each value if i change the integer. NSInteger index = 1; Mapdets *currentBranch = [[xmlParser branch] objectAtIndex:index]; NSString *title = currentBranch.title; – Cliffordwh Feb 28 '13 at 06:33
  • One more note, this is a multi array. So in here is 3-Objects and then each object has a array of items. – Cliffordwh Feb 28 '13 at 06:44
  • i guess you should follow above link provided by @rptwsthi, that's explain everything about adding annotation. – Baby Groot Feb 28 '13 at 06:46
  • Take Branch as (NSMutableArray) in Appdelegate and [appdelegate.branch addObject:currentBranch];...now u can use this array any where in u r App. – Hari1251 Feb 28 '13 at 07:12
  • Use NSUserDefault , follow this link http://stackoverflow.com/questions/13509999/i-have-nsstring-value-in-addviewcontroller-and-i-want-to-display-this-value-in-u/13619879#13619879 – Rajneesh071 Feb 28 '13 at 09:46

1 Answers1

1

Take Branch(NSMutableArray) in Appdelegate and

In u r .h file take AppDelegate reference

AppDelegate *appDelegate;

and in .m file In ViewDidLoad Method write this below line

appDelegate=(AppDelegate *)[[UIApplication sharedApplication] delegate];

and add this line [appdelegate.branch addObject:currentBranch]; instead of [self.branch addObject:currentBranch];

...now u can use this appdelegate.branch(Array) any where in u r App.

Anil Kothari
  • 7,653
  • 4
  • 20
  • 25
Hari1251
  • 452
  • 4
  • 15