Ios 在iphone mkmapview中获取触摸地图的当前位置
如何根据用户在iphone上触摸地图上的位置,在mkmapview中获取位置坐标 在mapview中添加Tap手势,并按照以下代码操作Ios 在iphone mkmapview中获取触摸地图的当前位置,ios,objective-c,mapkit,Ios,Objective C,Mapkit,如何根据用户在iphone上触摸地图上的位置,在mkmapview中获取位置坐标 在mapview中添加Tap手势,并按照以下代码操作 -(void)didTouchMap:(UITapGestureRecognizer*)tapGesure { CGPoint touchPoint = [tapGesure locationInView:selectLocationMapView]; CLLocationCoordinate2D coord= [selec
-(void)didTouchMap:(UITapGestureRecognizer*)tapGesure {
CGPoint touchPoint = [tapGesure locationInView:selectLocationMapView];
CLLocationCoordinate2D coord= [selectLocationMapView convertPoint:touchPoint toCoordinateFromView:selectLocationMapView];
NSLog(@"lat %f",coord.latitude);
NSLog(@"long %f",coord.longitude);
}
func touchsbegind(touchs:Set,带有事件:UIEvent?){
接触{
让touchPoint=touch.location(在:地图视图中)
让location=mapView.convert(接触点,到坐标From:mapView)
打印(\(位置.纬度),\(位置.经度)
}
}
当用户在mkmapview中触摸时,我想获取位置的坐标。我的意思是当用户触摸某个城市时,我想获取该位置的坐标。现在,我无法了解用户在mkmapview中所接触到的内容。您能理解我在mkmapview中显示注释的问题吗?希望[这][1]文章能够帮助您。[1]:
func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let touchPoint = touch.location(in: mapView)
let location = mapView.convert(touchPoint, toCoordinateFrom: mapView)
print ("\(location.latitude), \(location.longitude)")
}
}