【发布时间】:2025-12-11 12:00:01
【问题描述】:
我在 MKOverlayView 子类中画了一个圆圈。我有一个以米为单位的半径。我如何将所述米转换为点(在该缩放比例下)以在 drawMapRect:zoomScale:inContext: 中绘图?
【问题讨论】:
标签: cocoa mkmapview mapkit core-location
我在 MKOverlayView 子类中画了一个圆圈。我有一个以米为单位的半径。我如何将所述米转换为点(在该缩放比例下)以在 drawMapRect:zoomScale:inContext: 中绘图?
【问题讨论】:
标签: cocoa mkmapview mapkit core-location
查看标题:
帮手:
// 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];
【讨论】: