views:

225

answers:

1

I'm attempting to draw a circle around a point on a mapview, which I have successfully done, but not quite the way I wanted to. The CG methods are always going to be drawing relative to the screen size, and basically I want to draw things in meters, not pixels.

Anyone have experience doing this?

A: 

I don't have any experience doing what you describe above, but the MKMapView class has a set of methods for concerting Pixels to Coordinates and vice versa that you should be able to use to map your circle to Coordinates on the Map:

http://developer.apple.com/iphone/library/documentation/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html#//apple_ref/occ/instm/MKMapView/convertCoordinate:toPointToView:

This function may also come in handy for finding a point on the diamater of your circle to use with the above functions, providing you have your center point, the radius in meter of the circle, and the bearing in degrees.

-(CLLocation*) offsetLocation:(CLLocation*)startLocation:(double)offsetMeters:(double)bearing
{

        double EARTH_MEAN_RADIUS_METERS = 6372796.99;
        double lat2 = asin( sin(startLocation.coordinate.latitude) * cos(offsetMeters/EARTH_MEAN_RADIUS_METERS) + cos(startLocation.coordinate.latitude) * sin(offsetMeters/EARTH_MEAN_RADIUS_METERS) * cos(bearing) );
        double lon2 = startLocation.coordinate.longitude + atan2( sin(bearing) * sin(offsetMeters/EARTH_MEAN_RADIUS_METERS) * cos(startLocation.coordinate.latitude), cos(offsetMeters/EARTH_MEAN_RADIUS_METERS) - sin(startLocation.coordinate.latitude) * sin(lat2));
        CLLocation *tempLocation = [[CLLocation alloc] initWithLatitude:lat2 longitude:lon2];

        return tempLocation;
}
Eric Schweichler