MKMapView 未以图钉为中心

发布于 2024-09-01 20:01:40 字数 533 浏览 3 评论 0原文

我有一个 mkmapview,我当前正在向其添加引脚,但由于某种原因,当我调用 [mapView setRegion:[detailItem CoditionRegion]animated:YES]; 时,引脚偏离中心(朝右)屏幕一侧)在地图上。这是[deailItem坐标区域]的代码:

- (MKCoordinateRegion)coordinateRegion {
    MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
    region.center = self.coordinate;
    region.span.longitudeDelta = 0.0075f;
    region.span.latitudeDelta  = 0.0075f;
    return (region);
}

我将坐标区域的中心设置为对象的x,y坐标,那么为什么它在地图上偏离中心呢?我觉得我在这里缺少一些东西......

::Val::

I have an mkmapview that i'm currently adding pins to, but for some reason when I call [mapView setRegion:[detailItem coordinateRegion] animated:YES]; the pin is off-centered (toward the right side of the screen) on the map. Here is the code for [deailItem coordinateRegion]:

- (MKCoordinateRegion)coordinateRegion {
    MKCoordinateRegion region = { {0.0, 0.0 }, { 0.0, 0.0 } };
    region.center = self.coordinate;
    region.span.longitudeDelta = 0.0075f;
    region.span.latitudeDelta  = 0.0075f;
    return (region);
}

I'm setting the coordinateRegion's center to the object's x,y coordinate, so why is it off-center on the map? I feel like there's something I'm missing here...

::Val::

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

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

发布评论

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

评论(2

天煞孤星 2024-09-08 20:01:40

MKMapView 的界限是多少?选择注释后,您不必执行任何操作 ([mapView selectAnnotation:annotationAnimated:YES];)。

可能是您的 MKMapView 框架大于您的实际查看区域。地图居中,但视图未居中。

What are your bounds for MKMapView? You shouldn't have to do anything after you've selected the annotation ([mapView selectAnnotation:annotation animated:YES];).

It could be that your frame for MKMapView is bigger than your actual viewing area. The map is centered, but the view is not.

紫﹏色ふ单纯 2024-09-08 20:01:40

该文档讨论了垂直与水平跨度并不相同,因为一纬度不等于一经度。这种效应在两极会更加明显。应用区域后尝试使用 setCenter。有关跨度的进一步讨论,请参阅文档。

The documentation discusses this the vert vs. horizontal spans are not identical because one degree of latitude does not equal one degree of longitude. This effect will be more pronounced by the poles. Try using setCenter after you've applied the region. See the docs for further discussion of span.

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