读书人

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

发布时间: 2012-12-16 12:02:32 作者: rapoo

长按地图获取经纬度 添加图钉
长按地图获取经纬度
- (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]; }}

读书人网 >移动开发

热点推荐