@property (retain, nonatomic) NSMutableArray *posArrays;
// Handles the start of a touch
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.mapView removeOverlays:self.mapView.overlays];
if (!posArrays)
{
[posArrays removeAllObjects];
}
else
{
self.posArrays = [NSMutableArray array];
}
CGPoint touchPoint = [[[event allTouches] anyObject] locationInView:self.view];
CLLocationCoordinate2D beginCL =[mapView convertPoint:touchPoint toCoordinateFromView:self.view];
CLLocation *towerLocation = [[CLLocation alloc] initWithLatitude:beginCL.latitude longitude:beginCL.longitude];
[posArrays addObject:towerLocation];
[towerLocation release];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint touchPoint = [[[event allTouches] anyObject] locationInView:self.view];
CLLocationCoordinate2D beginCL =[mapView convertPoint:touchPoint toCoordinateFromView:self.view];
CLLocation *towerLocation = [[CLLocation alloc] initWithLatitude:beginCL.latitude longitude:beginCL.longitude];
[posArrays addObject:towerLocation];
[towerLocation release];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CLLocationCoordinate2D commuterLotCoords[[posArrays count]];
for (int i=0; i<[posArrays count]; i++)
{
commuterLotCoords[i]=[[posArrays objectAtIndex:i] coordinate];
}
NSLog(@"%@",posArrays);
MKPolygon *commuterPoly1 = [MKPolygon polygonWithCoordinates:commuterLotCoords count:[posArrays count]];
[self.mapView addOverlay:commuterPoly1];
}