用NSMutableArray 存储结构体 CLLocationCoordinate2D
@property (retain, nonatomic) NSMutableArray *posArrays;
// Handles the start of a touch
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.mapViewremoveOverlays:self.mapView.overlays];
if (!posArrays)
{
[posArraysremoveAllObjects];
}
else
{
self.posArrays = [NSMutableArrayarray];
}
CGPoint touchPoint = [[[eventallTouches] anyObject] locationInView:self.view];
CLLocationCoordinate2D beginCL =[mapViewconvertPoint:touchPoint toCoordinateFromView:self.view];
CLLocation *towerLocation = [[CLLocationalloc] initWithLatitude:beginCL.latitudelongitude:beginCL.longitude];
[posArrays addObject:towerLocation];
[towerLocation release];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint touchPoint = [[[eventallTouches] anyObject] locationInView:self.view];
CLLocationCoordinate2D beginCL =[mapViewconvertPoint:touchPoint toCoordinateFromView:self.view];
CLLocation *towerLocation = [[CLLocationalloc] initWithLatitude:beginCL.latitudelongitude:beginCL.longitude];
[posArrays addObject:towerLocation];
[towerLocation release];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CLLocationCoordinate2D commuterLotCoords[[posArrayscount]];
for (int i=0; i<[posArrayscount]; i++)
{
commuterLotCoords[i]=[[posArraysobjectAtIndex:i] coordinate];
}
NSLog(@"%@",posArrays);
MKPolygon *commuterPoly1 = [MKPolygonpolygonWithCoordinates:commuterLotCoords count:[posArrayscount]];
[self.mapViewaddOverlay:commuterPoly1];
}