gpt4 book ai didi

ios - 绘图针未指向 MKMapView 上的确切位置

转载 作者:行者123 更新时间:2023-11-29 10:57:15 25 4
gpt4 key购买 nike

- (void)viewDidLoad
{
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(foundTap:)];
tapRecognizer.numberOfTapsRequired = 1;
tapRecognizer.numberOfTouchesRequired = 1;
[self.myMapView addGestureRecognizer:tapRecognizer];
}

-(void)foundTap:(UITapGestureRecognizer *)recognizer
{
CGPoint point = [recognizer locationInView:self.myMapView];
CLLocationCoordinate2D tapPoint = [self.myMapView convertPoint:point toCoordinateFromView:self.view];
MKPointAnnotation *point1 = [[MKPointAnnotation alloc] init];
point1.coordinate = tapPoint;
[self.myMapView addAnnotation:point1];
}

当我在 MKMapView 中选择一个位置时,我使用上面的代码在 MKMapView 上定位它并没有指向我确切接触的地方。它离我接触的地方不远。我的代码有什么问题?任何帮助将不胜感激.提前致谢。

最佳答案

尝试将传入对象的locationInView:方法改为self.view:

-(void)foundTap:(UITapGestureRecognizer *)recognizer
{
CGPoint point = [recognizer locationInView:self.view];

CLLocationCoordinate2D tapPoint = [self.myMapView convertPoint:point toCoordinateFromView:self.view];

MKPointAnnotation *point1 = [[MKPointAnnotation alloc] init];

point1.coordinate = tapPoint;

[self.myMapView addAnnotation:point1];
}

关于ios - 绘图针未指向 MKMapView 上的确切位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17647853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com