当用户在视图中长按时,我想从地图视图中获取 GPS 坐标。
目前我正在使用:
- (void)viewDidLoad
{
[super viewDidLoad];
mapView.showsUserLocation =YES;
UILongPressGestureRecognizer *longPressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(mapLongPress:)];
longPressGesture.minimumPressDuration = 1.5;
[mapView addGestureRecognizer:longPressGesture];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)mapLongPress:(UILongPressGestureRecognizer *)gestureRecognizer{
if(gestureRecognizer.state == UIGestureRecognizerStateBegan){
CGPoint touchLocation = [gestureRecognizer locationInView:mapView];
CLLocationCoordinate2D coordinate;
coordinate = [mapView convertPoint:touchLocation toCoordinateFromView:mapView];// how to convert this to a String or something else?
NSLog(@"Longpress");
}
}
但是我如何获得坐标?从坐标 = [mapView convertPoint:touchLocation toCoordinateFromView:mapView];
?