0

我试图在地图视图上的一个点周围画一个圆圈,我已经成功地完成了,但不是我想要的方式。CG 方法总是相对于屏幕尺寸进行绘制,基本上我想以米为单位绘制东西,而不是像素。

有人有这样做的经验吗?

4

1 回答 1

0

我没有做你上面描述的任何经验,但是 MKMapView 类有一组用于将像素协调到坐标的方法,反之亦然,你应该能够使用这些方法将你的圆映射到地图上的坐标:

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

如果您有中心点、以米为单位的圆的半径和以度为单位的方位角,则此功能还可用于在您的圆的直径上找到一个点以与上述功能一起使用。

-(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;
}
于 2010-03-20T20:12:33.937 回答