读书人

用NSMutableArray 储存结构体 CLLocat

发布时间: 2012-06-20 20:37:21 作者: rapoo

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

}


读书人网 >其他相关

热点推荐