SeruK
SeruK

Reputation: 987

iOS MapKit - Points per meter

I am drawing a circle in a MKOverlayView subclass. I have a radius in meters. How would I convert said meters to points (at that zoom scale) for drawing in drawMapRect:zoomScale:inContext:?

Upvotes: 1

Views: 1250

Answers (1)

Daij-Djan
Daij-Djan

Reputation: 50109

see headers:

helpers:

 // 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);

and from the MKOverlayView

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

so

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

Upvotes: 3

Related Questions