iphone — convert MKMapPoint distances to meters

前端 未结 2 778
名媛妹妹
名媛妹妹 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."

    0 讨论(0)
  • 2021-01-07 03:14

    You can use the Haversine formula to calculate it, assuming that the earth is a perfect sphere.

    To understand how lat/lon vs meters works in the context of the earth, you may find it interesting to read about Nautical miles.

    You can find some more resources and some sample code by googling objective-c Haversine formula.

    Enjoy!

    0 讨论(0)
提交回复
热议问题