mapView 左下角的坐标偏离几个像素

发布于 2024-09-25 18:40:46 字数 719 浏览 3 评论 0原文

我试图将注释放在当前可见地图区域的左下角,尽管下面的代码

CLLocationCoordinate2D origin = getOriginOfRegion(mapView.region);
[[[SimpleAnnotation alloc] initWithCoords:origin] autorelease];
...
extern CLLocationCoordinate2D getOriginOfRegion(MKCoordinateRegion region){
    return CLLocationCoordinate2DMake(region.center.latitude-region.span.latitudeDelta/2,
                                  region.center.longitude-region.span.longitudeDelta/2);
}

(其中 SimpleAnnotation)非常简单;将定位点置于偏离实际角几度的位置:

右侧缩放级别较高,如您所见错误明显更小。

我尝试做一些数学来解决这个问题,考虑到错误可能与将椭圆坐标投影到平面上有关,但没有得出任何有用的结果。

有人解决这个问题了吗?我注意到地图视图上的纬度值不是“线性”的,我需要一些提示来理解如何转换它们。

I'm trying to put an Annotation the lower left corner of currently visible map region, although the following code

CLLocationCoordinate2D origin = getOriginOfRegion(mapView.region);
[[[SimpleAnnotation alloc] initWithCoords:origin] autorelease];
...
extern CLLocationCoordinate2D getOriginOfRegion(MKCoordinateRegion region){
    return CLLocationCoordinate2DMake(region.center.latitude-region.span.latitudeDelta/2,
                                  region.center.longitude-region.span.longitudeDelta/2);
}

where SimpleAnnotation is as simple as it gets; puts the pin point a few degrees off the actual corner:

On the right side zoom level is higher, and as you can see the mistake is significantly smaller.

I've tried doing some math to counter it, considering that the error may be something related to projecting elliptical coordinates onto a plane, but didn't come up with anything useful.

Has anyone solved this problem? I've noticed that latitude values are not 'linear' on a mapView, I need some hints to understand how to transform them.

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

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

发布评论

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

评论(1

飘然心甜 2024-10-02 18:40:46

我不知道这是否有效,但我建议您尝试让地图视图使用 convertPoint:toCooperativeFromView: 将视图坐标转换为地图坐标。

例如:

CGPoint bottomLeftPoint = CGPointMake(CGRectGetMinX(map.bounds), CGRectGetMaxY(map.bounds));
CLLocationCoordinate2D bottomLeftCoord = [map convertPoint:bottomLeftPoint toCoordinateFromView:map];

I don't know if this will work but I suggest you try letting the map view convert view coordinates to map coordinates with convertPoint:toCoordinateFromView:.

For example:

CGPoint bottomLeftPoint = CGPointMake(CGRectGetMinX(map.bounds), CGRectGetMaxY(map.bounds));
CLLocationCoordinate2D bottomLeftCoord = [map convertPoint:bottomLeftPoint toCoordinateFromView:map];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文