本文介绍了MKMapView:获取相对缩放比例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要得到一些缩放因子,它告诉我地图放大了多少(每当地区改变时)。



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



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

   - (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
//获取新值
CLLocationDegrees newdlat = mapView.region.span.latitudeDelta;

//找到缩放比例(使用经度代替?)
CGFloat zoomRatio = newdlat / olddlat;

//更新旧值(在别处定义)
olddlat = newdlat;
}

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

问题是当我滚动时检查经度和纬度变化值地图(不缩放)的值不断变化。如果地图不缩放,那么跨度值不应该保持不变?也许我误解了一些东西。



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



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



感谢您的任何帮助。

解决方案

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

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


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.

解决方案

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

这篇关于MKMapView:获取相对缩放比例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 06:38