iOS触摸的位置放一个大头针

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

iOS 触摸的位置放一个大头针

UITapGestureRecognizer *mTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapPRess:)];

[self.mapView addGestureRecognizer:mTap];

事件实现如下:

[cpp] view plaincopyprint?

- (void)tapPress:(UIGestureRecognizer*)gestureRecognizer {

CGPoint touchPoint = [gestureRecognizer locationInView:_mapView];//这里touchPoint是点击的某点在地图控件中的位置

CLLocationCoordinate2D touchMapCoordinate =

[_mapView convertPoint:touchPoint toCoordinateFromView:_mapView];//这里touchMapCoordinate就是该点的经纬度了

NSLog(@"touching %f,%f",touchMapCoordinate.latitude,touchMapCoordinate.longitude);

CLLocationCoordinate2D location=CLLocationCoordinate2DMake(touchMapCoordinate.latitude, touchMapCoordinate.longitude);

KCAnnotation *annotation=[[KCAnnotation alloc]init];

annotation.title=@"Kenshin&Kaoru";

annotation.subtitle=@"Kenshin Cui's Home";

annotation.coordinate=location;

annotation.image=[UIImage imageNamed:@"icon_paopao_waterdrop_streetscape.png"];

annotation.icon=[UIImage imageNamed:@"icon_mark2.png"];

annotation.detail=@"Kenshin Cui...";

annotation2.rate=[UIImage imageNamed:@"icon_Movie_Star_rating.png"];

[_mapView addAnnotation:annotation2];

}

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航