gpt4 book ai didi

iphone - 将跨度值转换为 map View 上的米

转载 作者:行者123 更新时间:2023-12-03 18:19:06 24 4
gpt4 key购买 nike

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

我需要的是MKCooperativeRegionMakeWithDistance的反函数来计算当前 map 跨度表示的距离。

我尝试了以下代码,但得到了错误的结果:

- (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);
}

如果我将 map 区域设置为 1500 米,结果会是 1800 米。

感谢您的帮助,文森特

最佳答案

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

- (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);
}

关于iphone - 将跨度值转换为 map View 上的米,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5270485/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com