MKMapView:获取相对缩放比例?

发布于 2024-09-03 21:58:51 字数 754 浏览 2 评论 0原文

我需要获得某种比例因子,它告诉我地图缩放了多少(每当区域发生变化时)。

我的第一个想法是使用跨度的纬度或经度增量值。我会跟踪“旧”值,然后在地图区域发生变化时更新该值,并将比率与旧值进行比较。

我正在使用以下委托方法:

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
    // Get the new value
    CLLocationDegrees newdlat = mapView.region.span.latitudeDelta;

    // Find the zoom ratio (use longitude instead?)
    CGFloat zoomRatio = newdlat / olddlat;

    // Update the old value (defined elsewhere)
    olddlat = newdlat;
}

在这种情况下,我没有使用经度增量,因为我认为它将与纬度成比例缩放,从而产生相同的比率(这是错误的吗?)。

问题是当我在滚动地图(不缩放)的同时检查经度和纬度增量的值时,值不断发生轻微变化。如果地图不缩放,跨度值是否应该保持不变?也许我误解了什么。

由于这个小小的变化,我担心我的缩放比例不够准确而无法依赖(最终我将使用它来缩放地图上的注释图像)。

我的主要问题是这是一个好的方法还是有一个我忽略的更简单的方法?

感谢您的任何帮助。

I need to get some kind of scaling factor which tells me by how much the map has zoomed (whenever the region changes).

My first idea was to use the span's delta latitude or longitude values. I would keep a track of the 'old' value and then update the value when the map region changes and compare the ratio with the old value.

I'm using the following delegate method:

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
    // Get the new value
    CLLocationDegrees newdlat = mapView.region.span.latitudeDelta;

    // Find the zoom ratio (use longitude instead?)
    CGFloat zoomRatio = newdlat / olddlat;

    // Update the old value (defined elsewhere)
    olddlat = newdlat;
}

I'm not using the longitude delta in this case because I figure it would scale proportionally to the latitude which would yield the same ratio (is this wrong?).

The problem is when I check the values of the longitude and latitude deltas while scrolling the map (without zooming) the values keep changing slightly. Shouldn't the span values stay the same if the map isn't zooming? Maybe I misunderstood something.

Due to this little variation I'm worried that my zoom ratio won't be accurate enough to rely on (ultimately I'm going to use it to scale annotation images with the map).

My main question is is this an good approach or is there a much simpler way that I'm overlooking?

Thanks for any help.

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

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

发布评论

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

评论(3

春花秋月 2024-09-10 21:58:55

地球是一个球体。地图就是一个平面。

为了在平面上绘制地球地图,一些变形是必要的。

在墨卡托投影中,经线没有扭曲,但纬线看起来是弯曲的。

因此,经度的增量将涉及恒定值,而纬度的增量则不然。因此,这种情况下的“刻度”(度/毫米)取决于测量棒的方向。

The Earth is a sphere. A map is a plane.

To map the Earth on a plane, some distortion is necessary.

In the Mercator projection the lines of longitude are not distorted but the lines of latitude appear curved.

Hence an increment in longitude will involve a constant value whereas the same is not true for an increment in latitude. Hence "scale" in this case (degrees/mm) depends on the orientation of the measuring stick.

葬花如无物 2024-09-10 21:58:54

通过在计算比率时使用经度而不是纬度解决了该问题。有关为什么会出现这种情况的详细信息,请参阅我对原始帖子的两条评论。

The problem was resolved by using longitude instead of latitude when calculating the ratio. See my two comments to the original post for details on why this is the case.

执手闯天涯 2024-09-10 21:58:53

在 Breadcrumb 示例代码中,使用以下方法计算 MKZoomScale。

MKZoomScale currentZoomScale = mapView.bounds.size.width / mapView.visibleMapRect.size.width;

http://developer.apple.com/library/ios/ #samplecode/Breadcrumb/Listings/Classes_BreadcrumbViewController_m.html

In the Breadcrumb sample code the compute MKZoomScale using the following approach.

MKZoomScale currentZoomScale = mapView.bounds.size.width / mapView.visibleMapRect.size.width;

http://developer.apple.com/library/ios/#samplecode/Breadcrumb/Listings/Classes_BreadcrumbViewController_m.html

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