用NSMutableArray 存储结构体 CLLocationCoordinate2D

来源:互联网 发布:从零开始学编程 编辑:程序博客网 时间:2024/06/05 13:27

@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];

}


原创粉丝点击