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] initWithConte开发者_如何学JAVAntsOfFile: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-
- What am i doing wrong?
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
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
精彩评论