mapView 左下角的坐标偏离几个像素
我试图将注释放在当前可见地图区域的左下角,尽管下面的代码
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道这是否有效,但我建议您尝试让地图视图使用
convertPoint:toCooperativeFromView:
将视图坐标转换为地图坐标。例如:
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: