在iPhone的MKMapView上触摸获取当前地图位置

6

如何在iPhone上根据用户触摸地图上的位置获取mkmapview中的位置坐标?


我想在用户触摸mkmapview时获取位置坐标。我的意思是,当用户触摸某个城市时,我想获取该位置的坐标。现在我无法获取用户在mkmapview中触摸的点。 - user811644
你能明白我在MKMapView中显示注释的问题吗? - user811644
希望本文能对您有所帮助。 - Anton Sivov
2个回答

3
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)")
    }
}

0
在您的地图视图中添加TapGesture并按照以下代码操作。
-(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);

}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接