假设我有一个包含四个CLLocationCoordinate2D点的正方形,分别位于lat和lon中,我想找到以米为单位的正方形面积。我将CLLocationCoordinate2D点转换为MKMapPoints,然后在X-Y空间中找到了该区域。但是,我发现的区域是以MKMapPoint为单位的,不会直接转换为米。如何将MKMapPoint-space中的该区域转换回米?
最佳答案
MapKit函数MKMetersBetweenMapPoints
使此操作更容易。
例如,如果要获取当前显示区域的面积,请执行以下操作:
MKMapPoint mpTopLeft = mapView.visibleMapRect.origin;
MKMapPoint mpTopRight = MKMapPointMake(
mapView.visibleMapRect.origin.x + mapView.visibleMapRect.size.width,
mapView.visibleMapRect.origin.y);
MKMapPoint mpBottomRight = MKMapPointMake(
mapView.visibleMapRect.origin.x + mapView.visibleMapRect.size.width,
mapView.visibleMapRect.origin.y + mapView.visibleMapRect.size.height);
CLLocationDistance hDist = MKMetersBetweenMapPoints(mpTopLeft, mpTopRight);
CLLocationDistance vDist = MKMetersBetweenMapPoints(mpTopRight, mpBottomRight);
double vmrArea = hDist * vDist;
文档指出,该功能考虑了“地球的曲率”。
关于iphone - iphone —将MKMapPoint距离转换为米,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7395925/