iphone - 将MKMapPoint距离转换为米 [英] iphone -- convert MKMapPoint distances to meters

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

问题描述

假设我有一个由四个CLLocationCoordinate2D点组成的正方形,这些点位于lat,lon,我想要以米为单位查找正方形的面积。我将CLLocationCoordinate2D点转换为MKMapPoints,并在X-Y空间中找到该区域。但是,我发现的区域是MKMapPoint的单位,它不直接转换为米。 MapKit函数 MKMetersBetweenMapPoints

如何将MKMapPoint空间中的这个区域转换回米?

/ code>使得这一点更容易。



例如,如果您想获取当前显示区域的区域:

  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 。高度);

CLLocationDistance hDist = MKMetersBetweenMapPoints(mpTopLeft,mpTopRight);
CLLocationDistance vDist = MKMetersBetweenMapPoints(mpTopRight,mpBottomRight);

double vmrArea = hDist * vDist;

该文件指出该函数需要考虑地球的曲率。


Say I have a square which consists of four CLLocationCoordinate2D points, which are in lat, lon, and I want to find the area of the square in meters. I convert the CLLocationCoordinate2D points into MKMapPoints, and I find the area in X-Y space. However, the area I find is in the units of MKMapPoint, which don't directly translate to meters. How can I translate this area in MKMapPoint-space back into meters?

解决方案

The MapKit function MKMetersBetweenMapPoints makes this easier.

For example, if you wanted to get the area of the currently displayed region:

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;

The documentation states that the function takes "into account the curvature of the Earth."

这篇关于iphone - 将MKMapPoint距离转换为米的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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