像标题一样,是否有人知道如何计算每个区域的尺寸宽度到米,意味着在每个地方和任何缩放.
我找到了如何获得zoomScale.
CLLocationDegrees longitudeDelta = myMapView.region.span.longitudeDelta;
CGFloat mapWidthInPixels = myMapView.bounds.size.width;
double zoomScale = longitudeDelta * MERCATOR_RADIUS * M_PI / (180.0 * mapWidthInPixels);
Run Code Online (Sandbox Code Playgroud)
但我不知道结果意味着什么,如果我想获得尺寸宽度的米或者可能是20f的线,我将mapWidthInPixels更改为20是否正确?
您可以在此处找到对公式的详细说明:将经度纬度转换为米.
示例代码:
CLLocationDegrees deltaLatitude = self.mapView.region.span.latitudeDelta;
CLLocationDegrees deltaLongitude = self.mapView.region.span.longitudeDelta;
CGFloat latitudeCircumference = 40075160 * cos(self.mapView.region.center.latitude * M_PI / 180);
NSLog(@"x: %f; y: %f", deltaLongitude * latitudeCircumference / 360, deltaLatitude * 40008000 / 360);
Run Code Online (Sandbox Code Playgroud)
这对我很有用.我的解决方案是在Swift中,但是Obj-C是类似的.
斯威夫特:
let mRect: MKMapRect = self.mapView.visibleMapRect
let eastMapPoint = MKMapPointMake(MKMapRectGetMinX(mRect), MKMapRectGetMidY(mRect))
let westMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect), MKMapRectGetMidY(mRect))
let currentDistWideInMeters = MKMetersBetweenMapPoints(eastMapPoint, westMapPoint)
let milesWide = currentDistWideInMeters / 1609.34 // number of meters in a mile
println(milesWide)
Run Code Online (Sandbox Code Playgroud)
Obj-C(赞美以下代码的原始撰稿人/sf/answers/406952661/)
MKMapRect mRect = self.mapView.visibleMapRect;
MKMapPoint eastMapPoint = MKMapPointMake(MKMapRectGetMinX(mRect), MKMapRectGetMidY(mRect));
MKMapPoint westMapPoint = MKMapPointMake(MKMapRectGetMaxX(mRect), MKMapRectGetMidY(mRect));
self.currentDistWideInMeters = MKMetersBetweenMapPoints(eastMapPoint, westMapPoint);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3796 次 |
| 最近记录: |