长按地图获取经纬度 添加图钉

长按地图获取经纬度
[quote]

UILongPressGestureRecognizer *lpress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
lpress.minimumPressDuration = 0.3;//按0.5秒响应longPress方法
lpress.allowableMovement = 10.0;
//给MKMapView加上长按事件
[mapView addGestureRecognizer:lpress];//mapView是MKMapView的实例
[lpress release];

- (void)longPress:(UIGestureRecognizer*)gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateBegan){ //这个状态判断很重要
//坐标转换
CGPoint touchPoint = [gestureRecognizer locationInView:self.mapView];
CLLocationCoordinate2D touchMapCoordinate =
[self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView];
//这里的touchMapCoordinate.latitude和touchMapCoordinate.longitude就是你要的经纬度,
NSLog(@"%f",touchMapCoordinate.latitude);
NSLog(@"%f",touchMapCoordinate.longitude);
}
}
[/quote]

长按添加图钉

- (void)longPress:(UIGestureRecognizer*)gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateBegan){ //这个状态判断很重要
//坐标转换
CGPoint touchPoint = [gestureRecognizer locationInView:self.mapView];
CLLocationCoordinate2D touchMapCoordinate =
[self.mapView convertPoint:touchPoint toCoordinateFromView:self.mapView];
//这里的touchMapCoordinate.latitude和touchMapCoordinate.longitude就是你要的经纬度,
NSLog(@"%f",touchMapCoordinate.latitude);
NSLog(@"%f",touchMapCoordinate.longitude);
//30.264998 120.122538 30.285012 120.117989
LocationObject *aLocationObject = [[LocationObject alloc]initWithTitle:@"hello" latitue:touchMapCoordinate.latitude longitude:touchMapCoordinate.longitude];
aLocationObject._subTitleString = @"world";
NSMutableArray *_mapAnnotations = [[NSMutableArray alloc]initWithCapacity:1];
[_mapAnnotations addObject:aLocationObject];
[self.mapView addAnnotations:_mapAnnotations ];
[_mapAnnotations release];
[aLocationObject release];

}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值