我想在用户长时间按下视图时从地图视图中获取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];
?
答案 0 :(得分:1)
在代码中回答您的问题:
“如何将此转换为字符串或其他内容?”
NSLog(@"LongPress coordinate: latitude = %f, longitude = %f", coordinate.latitude, coordinate.longitude);
地理坐标由latitdue和经度表示
使用ios,您可以使用CLLocationCoordinate2D
,其中包含坐标成分纬度和经度。
latitdue的范围是[-90.0,90.0]
经度范围[-180.0,180.0]
您可以使用CLLocationCoordinate2D
或您自己的结构来存储它。