iPhone MapKit:通过触摸 MKMapView 手动选择位置(坐标)

发布于 2024-09-14 05:48:00 字数 227 浏览 4 评论 0原文

我想为用户提供(手动)选择纬度的可能性。又长。通过触摸 MKMapView 进行坐标。我怎样才能做到这一点?

我已经看到 MKMapView 委托提供了方法 convertPoint:toCooperativeFromView: 。我认为,这可能是一个好的开始,但我不知道如何通过触摸动作创建一个点。

我将不胜感激任何帮助。谢谢。

I would like to offer the user the possibility to (manually) select lat. and long. coordinates by touching a MKMapView. How can I achieve that?

I've seen that the MKMapView delegate offers the method convertPoint:toCoordinateFromView: . I think, that could be a good starting, but I don't know how to create a point from a touch action.

I would appreciate any help. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡淡的优雅 2024-09-21 05:48:01

vwMapMKMapview 对象的名称:

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(foundTap:)]; 
tapRecognizer.numberOfTapsRequired = 1;
tapRecognizer.numberOfTouchesRequired = 1; 
[vwMap addGestureRecognizer:tapRecognizer];



-(IBAction)foundTap:(UITapGestureRecognizer *)recognizer {
    CGPoint point = [recognizer locationInView:vwMap];
    CLLocationCoordinate2D tapPoint = [vwMap convertPoint:point toCoordinateFromView:vwMap];

    MKPointAnnotation *point1 = [[MKPointAnnotation alloc] init]; 
    point1.coordinate = tapPoint;

    [vwMap addAnnotation:point1];
}

vwMap is the name of MKMapview object:

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(foundTap:)]; 
tapRecognizer.numberOfTapsRequired = 1;
tapRecognizer.numberOfTouchesRequired = 1; 
[vwMap addGestureRecognizer:tapRecognizer];



-(IBAction)foundTap:(UITapGestureRecognizer *)recognizer {
    CGPoint point = [recognizer locationInView:vwMap];
    CLLocationCoordinate2D tapPoint = [vwMap convertPoint:point toCoordinateFromView:vwMap];

    MKPointAnnotation *point1 = [[MKPointAnnotation alloc] init]; 
    point1.coordinate = tapPoint;

    [vwMap addAnnotation:point1];
}
星星的軌跡 2024-09-21 05:48:01

一个 UITouch 对象(请参阅 此处)有 API:

- (CGPoint)locationInView:(UIView *)view

然后使用您确定的 MKMapView API。

A UITouch object (see here) has the API:

- (CGPoint)locationInView:(UIView *)view

Then use the MKMapView API you identified.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文