MKMapView setRegion" snaps"到预定义的缩放级别? [英] MKMapView setRegion "snaps" to predefined zoom levels?

查看:111
本文介绍了MKMapView setRegion" snaps"到预定义的缩放级别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以确认setRegion捕捉到预定义的缩放级别以及此行为是否与设计(虽然未记录)或已知错误一样?具体来说,似乎setRegion捕捉到与用户双击地图时使用的缩放级别相对应的相同缩放级别。

Can anyone confirm that setRegion "snaps" to predefined zoom levels and whether or not this behavior is as designed (although undocumented) or a known bug? Specifically, it appears that setRegion snaps to the same zoom levels that correspond to the zoom levels used when the user double-taps the map.

我正在尝试恢复以前保存的区域,但如果保存的区域是通过捏缩放而不是双击缩放设置的,则此行为无法实现。

I'm trying to restore a previously saved region but this behavior makes it impossible if the saved region was set via a pinch zoom and not a double-tap zoom.

一个很大的线索让我知道事情是如果我在地图的当前区域调用regionThatFits,那么在mapkit方面会出现问题。它应返回相同的区域(因为它显然适合地图的框架),但它返回的区域对应于下一个更高的预定义缩放级别。

A big clue to me that things are broken on the mapkit side is what occurs if I call regionThatFits on the map's current region. It should return the same region (since it obviously fits the map's frame) but it returns the region that corresponds to the next higher predefined zoom level instead.

setVisibleMapRect的行为类似。

setVisibleMapRect behaves similarly.

任何进一步的见解或信息都将受到赞赏。

Any further insight or information would be appreciated.

我发现了这些相关的帖子,但都没有包含解决方案或明确确认这实际上是一个mapkit错误:

I found these related posts but neither included a solution or definitive confirmation that this is in fact a mapkit bug:

MKMapView setRegion:奇怪的行为?

MKMapView显示错误保存的区域

编辑:

这是一个演示该问题的示例。所有值对我的地图视图的宽高比都有效:

Here is an example that demonstrates the problem. All values are valid for my map view's aspect ratio:

MKCoordinateRegion initialRegion;
initialRegion.center.latitude = 47.700200f;
initialRegion.center.longitude = -122.367109f;
initialRegion.span.latitudeDelta = 0.065189f;
initialRegion.span.longitudeDelta = 0.067318f;
[map setRegion:initialRegion animated:NO];
NSLog(@"DEBUG initialRegion:  %f  %f  %f  %f", initialRegion.center.latitude, initialRegion.center.longitude, initialRegion.span.latitudeDelta, initialRegion.span.longitudeDelta);
NSLog(@"DEBUG map.region:  %f  %f  %f  %f", map.region.center.latitude, map.region.center.longitude, map.region.span.latitudeDelta, map.region.span.longitudeDelta);

输出:

DEBUG initialRegion:  47.700199  -122.367111  0.065189  0.067318
DEBUG map.region:  47.700289  -122.367096  0.106287  0.109863

请注意纬度/经度增量值的差异。地图的值几乎是我要求的两倍。较大的值对应于用户双击地图时使用的缩放级别之一。

Note the discrepancy in the latitude/longitude delta values. The map's values are almost double what I requested. The larger values correspond to one of the zoom levels used when the user double-taps the map.

推荐答案

是的,它会捕捉到离散水平。我做了很多实验,似乎像每个像素经度的2.68220906e-6度的倍数。

Yes, it snaps to discrete levels. I've done quite a bit of experimentation, and it seems to like multiples of 2.68220906e-6 degrees of longitude per pixel.

因此,如果您的地图填满整个屏幕宽度,第一个等级跨越.0008583度,那么您可以得到的下一个等级是两倍,.001717,然后下一个是两倍,.003433,依此类推。我不确定他们为什么选择经度标准化,这意味着修正缩放级别取决于您所看到的世界的哪个部分。

So if your map fills the whole width of the screen, the first level spans .0008583 degrees, then the next level up you can get is twice that, .001717, and then the next one is twice that, .003433, and so on. I'm not sure why they chose to normalize by longitude, it means that fixes zoom levels vary depending on what part of the world you are looking at.

我也花了很多时间试图理解这个数字的重要性.68220906e-6度。它出现在赤道约30厘米,这是有道理的,因为谷歌地图使用的高分辨率照片具有30厘米的分辨率,但我希望他们使用纬度而不是经度来建立缩放级别。这样,在最大变焦时,你总是保留卫星图像的原始分辨率,但谁知道,他们可能有一些聪明人的理由让它像那样工作。

I've also spent a lot of time trying to understand the significance of that number .68220906e-6 degrees. It comes out to about 30cm at the equator, which kind of makes sense since the high resolution photos used by Google Maps have a 30cm resolution, but I would have expected them to use latitude instead of longitude to establish the zoom levels. That way, at maximum zoom, you always the native resolution of the satellite images, but who knows, they probably have some smart-people reason for making it work like that.

在我的应用程序中,我需要显示一定范围的纬度。我将使用一些代码来尝试尽可能地缩放地图。如果有人有兴趣,请与我联系。

In my application I need to display a certain range of latitude. I'm gonna work on some code to try to zoom the map as close as possible to that. If anyone is interested, contact me.

这篇关于MKMapView setRegion" snaps"到预定义的缩放级别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆