在 MKMapView 上绘制指定尺寸(以米为单位)的元素

发布于 2024-08-26 07:18:47 字数 113 浏览 2 评论 0原文

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

有人有这样做的经验吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱殇璃 2024-09-02 07:18:47

我没有任何执行您上面描述的操作的经验,但是 MKMapView 类有一组用于将像素与坐标协调一致的方法,反之亦然,您应该能够使用它们将圆映射到地图上的坐标:

http://developer.apple.com/iphone/library/documentation/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html#//apple_ref/occ/instm/MKMapView/convertCooperative: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;
}

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;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文