7.点击哪个位置在该位置新增一个大头针

#pragma mark点击哪个位置在该位置新增一个大头针

//在地图上操作大头针实际上操作的是大头针数据模型

//添加大头针:添加一个大头针数据模型

//移除大头针:删除一个大头针数据模型

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent*)event{

UITouch* t = [touchesallObjects].firstObject;

CGPoint point = [t locationInView:self.mapView];

CLLocationCoordinate2D coordinate2D = [self.mapView convertPoint:point toCoordinateFromView:self.mapView];

[self addAnnotationWithCoordinate2D:coordinate2D titilt:@"新白鹿" subtitle:@"城惠玩2"];

}

- (void)addAnnotationWithCoordinate2D:(CLLocationCoordinate2D)coordinate2D titilt:(NSString*)titile subtitle:(NSString*)subtitle {

//1.创建一个大头针数据模型

YBAnnotation* point = [[YBAnnotation alloc]init];

if(arc4random_uniform(10) %2) {

point = [[YBAnnotationShop alloc]init];

}

point.title= titile;

point.subtitle= subtitle;

[point setCoordinate:coordinate2D];

//2.添加数据模型到地图

//判断是否已经添加了该大头针数据模型

if([self.mapView.annotations containsObject:point]) {

return;

}

[self.mapView addAnnotation:point];

}

你可能感兴趣的:(7.点击哪个位置在该位置新增一个大头针)