添加长按手势,在地图上加注解标识

来源:互联网 发布:软件架构之美 编辑:程序博客网 时间:2024/04/27 14:23

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(pick:)];//添加手势

    [mapView addGestureRecognizer:longPress];

实现pick:方法

 

//长按手势处理方法

- (void)pick:(id)sender{

    CGPoint pickPoint = [(UILongPressGestureRecognizer *)sender locationInView:mapView];//取到长按的点

    NSLog(@"%f,%f",pickPoint.x,pickPoint.y);

   // - (CLLocationCoordinate2D)convertPoint:(CGPoint)point toCoordinateFromView:(UIView *)view

    CLLocationCoordinate2D coornation = [mapView convertPoint:pickPoint toCoordinateFromView:mapView];//获取经纬度

    

    MyAnotation *ann = [[MyAnotation alloc] init];//初始化注解对象

    ann.coordinate = coornation;//定位经纬度

    [self.mapView addAnnotation:ann];//添加注解

    

}

0 0
原创粉丝点击