【问题标题】:iOS MapKit - Points per meteriOS MapKit - 每米点数
【发布时间】:2025-12-11 12:00:01
【问题描述】:

我在 MKOverlayView 子类中画了一个圆圈。我有一个以米为单位的半径。我如何将所述米转换为点(在该缩放比例下)以在 drawMapRect:zoomScale:inContext: 中绘图?

【问题讨论】:

    标签: cocoa mkmapview mapkit core-location


    【解决方案1】:

    查看标题:

    帮手:

     // Conversion between distances and projected coordinates
     MK_EXTERN CLLocationDistance MKMetersPerMapPointAtLatitude(CLLocationDegrees latitude) NS_AVAILABLE(NA, 4_0);
     MK_EXTERN double MKMapPointsPerMeterAtLatitude(CLLocationDegrees latitude) NS_AVAILABLE(NA, 4_0);
    
     MK_EXTERN CLLocationDistance MKMetersBetweenMapPoints(MKMapPoint a, MKMapPoint b) NS_AVAILABLE(NA, 4_0);
    

    并来自 MKOverlayView

     // Convert screen points relative to this view to absolute MKMapPoints
     - (CGPoint)pointForMapPoint:(MKMapPoint)mapPoint;
     - (MKMapPoint)mapPointForPoint:(CGPoint)point;
    

    所以

    double ppm = MKMapPointsPerMeterAtLatitude(centerCoordinate.latitude);
    MKMapPoint mkptLeftmost = ptCenter.x -= ppm;
    CGPoint ptLeftmost  = [self pointForMapPoint:mkptLeftmost];
    

    【讨论】:

    • 内联输入 - 不保证......但这就是方法
    • 我会接受这个,因为这是一个不错的答案。我认为我遇到的问题是无关的。