开发者

Drawing elements on an MKMapView of a specified size in meters

开发者 https://www.devze.com 2022-12-23 20:01 出处:网络
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

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?


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号