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];
}
|
新聞熱點
疑難解答