在 MKMapView 上绘制大圆叠加线
我正在尝试在 MKMapView 上的两个纬度/经度点之间绘制一条大圆线。这是一条显示为圆形的线(地球仪上的“直线”),最好在此处进行可视化。事实上,这个非常奇怪的 WordPress 网站似乎开始准确地描述如何做到这一点,但它在前几个步骤后突然结束。
阅读Apple的文档我看到
在 iOS 4.0 及更高版本中,您还可以使用投影地图坐标而不是区域来指定某些值。当您将地球的曲面投影到平面上时,您会得到二维版本的地图,其中经线看起来是平行的。此地图上的位置和距离是使用 MKMapPoint、MKMapSize 和 MKMapRect 数据类型指定的。您可以使用这些数据类型来指定地图的可见区域以及指定叠加层的位置。
我不确定如何将其应用到大圆叠加层。有人可以帮忙吗?
I'm trying to draw a Great Circle line between two lat/lon points on an MKMapView. This is a line that would appear rounded (a 'straight' line on a globe) and is best visualized here. In fact this very odd WordPress site seems to begin to describe exactly how to do this, but it ends abruptly after the first few steps.
Reading in Apple's documentation I see
In iOS 4.0 and later, you can also use projected map coordinates instead of regions to specify some values. When you project the curved surface of the globe onto a flat surface, you get a two-dimensional version of a map where longitude lines appear to be parallel. Locations and distances on this map are specified using the MKMapPoint, MKMapSize, and MKMapRect data types. You can use these data types to specify the map’s visible region and when specifying the location of overlays.
How I would apply this to a Great Circle overlay I'm not sure. Can anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我已经实现了这个,以便使用 MKPolyline 为在两个机场之间飞行的飞机绘制一条大圆航线。
您现在已经创建了覆盖层,现在您只需要在mapView:viewForOverlay 中提供一个MKOverlayView 即可。
希望这有帮助。
屏幕截图 http://s1-03.twitpicproxy.com/photos/large/489178500.png
I've implemented this for drawing a great circle route for aircraft going between two airports using MKPolyline.
You've now created the overlay(s), now you just need to provide an MKOverlayView in mapView:viewForOverlay.
Hope this helps.
Screenshot http://s1-03.twitpicproxy.com/photos/large/489178500.png
虽然游戏已晚,但值得一提
MKGeodesicPolyline
,自 iOS 7.0 以来的新功能,它“追踪沿地球表面的最短路径”。这样,创建和添加测地折线类型的
MKPolylineOverlay
就变得很简单。记得包含渲染器并给mapView一个委托:
It is late in the game, but worth mentioning
MKGeodesicPolyline
, new since iOS 7.0, which 'traces the shortest path along the surface of the Earth'.With this it becomes simple to create and add an
MKPolylineOverlay
of type Geodesic Polyline.remember to include the renderer and give the mapView a delegate:
这可以通过创建 MKOverlayPathView 类的子类来完成。您需要重写 (void)createPath 方法,基本上您可以使用 UIBezierPath 来创建弧,或者直接创建弧作为路径,这是可能的,但我还没有这样做。
在方法上定义路径后,您需要使用新创建的路径设置类的路径属性。这样,路径的渲染将自动完成。
希望这有帮助。
This can be accomplish creating a subclass of the MKOverlayPathView class. You need to override the (void)createPath method, and basically you could use a UIBezierPath to create the arc, or create an arc as path directly, which is possible but I haven't done it yet.
Once you define the path on the method, you need to set the path property of the class with the newly created path. That way, the rendering of the path is going to be done automatically.
Hope this helps.
numsegs 参数应该可以根据地图缩放级别和两点的距离进行更改。两点的纬度/经度坐标可以转换为像素坐标。因此,numsegs 参数可以被视为像素差异的函数。
The numsegs parameter should be changeable according to the map zoom level and the distance of the two points. The lat/lon coordinate of the two points can be transformed into pixel coordinate. Thus the numsegs parameter can be viewed as a function of pixel differences.