gpt4 book ai didi

ios - 如何检索 map 标注坐标?

转载 作者:行者123 更新时间:2023-11-29 04:45:03 25 4
gpt4 key购买 nike

我想要一个 IBAction 将我的 map View 区域放在注释上。注释被添加到 map View 中,如下所示:

myAnnotation *pinLoc=[[myAnnotation alloc] init];
pinLoc.coordinate = mapview.centerCoordinate;
pinLoc.title = @"Title";
pinLoc.subtitle = @"subtitle";
[mapview addAnnotation:pinLoc];

我想检索它并以某种方式移动该区域的中心:

- (IBAction)findPin:(id)sender {

MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };

region.center.latitude = pinLoc.coordinate.latitude;
region.center.longitude = pinloc.coordinate.longitude;
region.span.latitudeDelta = 0.001f;
region.span.longitudeDelta = 0.001f;
[mapview setRegion:region animated:YES];
[mapview setDelegate:self];
}

我也在寻找一种方法来判断引脚是否在多边形内。我已经使用用户位置进行了工作,但同样,我需要检索图钉的坐标以使其也可以与图钉一起使用。

最佳答案

最简单的方法是在添加注释时存储对注释的引用。

例如,您可以声明一个名为 pinToRemember 且类型为 myAnnotation 的保留属性,并在添加注释后执行以下操作以将其保存以供以后使用:

[mapview addAnnotation:pinLoc];
self.pinToRemember = pinLoc;

然后在 findPin: 中,您将执行以下操作:

if (pinToRemember == nil)
return;

region.center = pinToRemember.coordinate;


或者,您可以搜索 map View 的 annotations 数组属性,并通过查找其 title 或其他自定义属性来查找您感兴趣的注释。这可以通过使用简单的 for 循环来完成。


您说您有“判断引脚是否在多边形内的方法”,但这个答案也可能有用:
How to determine if an annotation is inside of MKPolygonView (iOS)

关于ios - 如何检索 map 标注坐标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9780814/

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