I add a NSTimer to record the location from location manager ,and put ever location into a NSMutableArray.
-(void)OnTimer:(NSTimer *)param{
[self.locationRecoder addObject:self.manager.location];
}
and I add a button to UI, when I click the button, it invoke this method
-(IBAction)Click:(id)sender(){
NSArray *coordinateArray = [self.locationRecorder valueForKeyPath:@"coordinate"];
MKPolyline *lines = [MKPolyline ploylineWithCoordinates:(CLLocationCoordinate2D *)coordinateArray count:coordinateArray.count];
[self.map addOverlay:lines];
}
then there is nothing drawn. did i do something wrong in type cast?
The
polylineWithCoordinatesmethod requires a plain C array of structs of typeCLLocationCoordinate2D.After the call to
valueForKeyPath,coordinateArrayis anNSArrayofNSValueobjects.That is not the same thing as a C array of structs.
Casting that
NSArrayto(CLLocationCoordinate2D *)doesn’t convert it to a C array of structs.Instead, you have to create the C array manually using
mallocand looping through thelocationRecoderarray: