Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create CLLocationCoordinate2D from array

Tags:

iphone

mapkit

I have a plist with dictionary of array's with coordinates (stored as strings).

I want to create a CLLocationCoordinate2D from every array and crate an overlay for the map.

I did that -

NSString *thePath = [[NSBundle mainBundle]  pathForResource:@"Roots" ofType:@"plist"];
    NSDictionary *pointsDic = [[NSDictionary alloc] initWithContentsOfFile:thePath];

 NSArray *pointsArray = [NSArray arrayWithArray:[pointsDic objectForKey:@"roade1"]];

 CLLocationCoordinate2D pointsToUse[256];

 for(int i = 0; i < 256; i++) {
  CGPoint p = CGPointFromString([pointsArray objectAtIndex:i]);
  pointsToUse[i] = CLLocationCoordinate2DMake(p.x,p.y);
  NSLog(@"coord %f",pointsToUse [i].longitude);
  NSLog(@"coord %f",pointsToUse [i].latitude);

 }

 MKPolyline *myPolyline = [MKPolyline polylineWithCoordinates:pointsToUse count:256];

 [[self mv] addOverlay:myPolyline];

but the app is crashing without any error. (BTW when i remove the addOverLay method the app does not crash).

I have 2 questions-

  1. What am i doing wrong?
  2. I have tried to set the pointsArray count as the argument for the CLLocationCoordinate2D like that -

    CLLocationCoordinate2D pointsToUse[pointsArray count];

And i am getting an error. How can i set the CLLocationCoordinate2D dynamically ?

Thanks for any help. Shani

like image 824
shannoga Avatar asked Jan 04 '11 23:01

shannoga


1 Answers

O.K The problem was indeed in the viewForOverlay method (thanks aBitObvious and all the rest). It appears that the line loading of the point from the array is working good.

and for the second question i just separated it to 2 steps:

  NSInteger c = [pointsArray count];
    CLLocationCoordinate2D pointsToUse[c];

and it worked fine, so if any one is looking for a way to load overlayes from plist, that way is working for me.

Thanks shani

like image 119
shannoga Avatar answered Nov 07 '22 15:11

shannoga