在mapview上将跨度值转换为米 [英] Convert span value into meters on a mapview

查看:94
本文介绍了在mapview上将跨度值转换为米的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当用户放大或缩小地图时,我都需要知道地图上当前表示了多少米(宽度或高度)。

Whenever the user zoom in or out the map i need to know how many meters are currently represented on the map (width or height).

我需要的是 MKCoordinateRegionMakeWithDistance 的反函数来计算当前地图范围所代表的距离。

What i need is the inverse function of MKCoordinateRegionMakeWithDistance to calculate the distance represented by the current map span.

我尝试了以下代码,但结果出错:

I tried the following code but i get wrong results :

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
    MKMapRect mRect = self.map.visibleMapRect;
    MKMapPoint northMapPoint = MKMapPointMake(MKMapRectGetMidX(mRect), MKMapRectGetMinY(mRect));
    MKMapPoint southMapPoint = MKMapPointMake(MKMapRectGetMidX(mRect), MKMapRectGetMaxY(mRect));

    self.currentDist = MKMetersBetweenMapPoints(northMapPoint, southMapPoint);
}

如果我将地图区域设置为1500米,我会得到像1800这样的东西结果..

If i set the map region to 1500 meters i get something like 1800 as a result..

感谢您的帮助,
Vincent

Thanks for your help, Vincent

推荐答案

实际上这是一个非常愚蠢的错误,如果我沿着X轴进行相同的操作,那么我得到正确的值:

Actually it was a really stupid mistake, if i do the same operation along the X axis then i get the correct value :

- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated {
MKMapRect mRect = self.map.visibleMapRect;
MKMapPoint eastMapPoint = MKMapPointMake(MKMapRectGetMinX(mRect), MKMapRectGetMidY(mRect));
MKMapPoint westMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect), MKMapRectGetMidY(mRect));

self.currentDist = MKMetersBetweenMapPoints(eastMapPoint, westMapPoint);
}

这篇关于在mapview上将跨度值转换为米的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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