iphone — convert MKMapPoint distances to meters

前端 未结 2 791
名媛妹妹
名媛妹妹 2021-01-07 02:32

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 CLLocati

2条回答
  •  难免孤独
    2021-01-07 03:12

    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."

提交回复
热议问题