MKMapView 叠加层不显示在地图上
我的应用程序从谷歌获取路线的积分。响应还包含边界矩形。我的应用程序创建矩形并正确显示地图,然后添加叠加层。 调用叠加层
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)
并从这些点构造一个 MKOverlayPathView 。我已经验证这些点位于边界矩形内。但是,路线叠加层不会绘制在显示的地图上。
我已经检查了我能想到的一切,没有任何喜悦,任何建议将不胜感激。
My app gets the points for a route from google. The response also contains the bounding rect. My app creates the rect and shows the map correctly and I add the overlay. The
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)
overlay is called and I construct a MKOverlayPathView
from the points. I have verified that the points are within the bounding rect. However, the route overlay does not draw on the displayed map.
I have checked everything I can think of with no joy, any suggestions would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我还不知道为什么叠加层没有显示,但请在一个全新的项目中尝试以下代码。
在我的测试中,我将地图视图控件添加到 xib,然后将 IBOutlet 和地图视图的委托出口连接到文件的所有者。在代码中创建地图视图也可以(只是不要将其添加到 xib 并确保设置
delegate
属性)。这是我的测试
TRTrip
类:在视图控制器的
viewDidLoad
中,我添加一个MKPointAnnotation
、MKCircle
、TRTrip
,以及地图上的MKPolyline
:这是
viewForOverlay
方法:这是结果:
顶部的红线是
TRTrip
,底部的紫色线是MKPolyline
。I don't know yet why the overlay isn't showing but try the following code in a fresh, new project.
In my test, I added the map view control to the xib and then connected the IBOutlet and the map view's delegate outlet to File's Owner. Creating the map view in code will also work (just don't also add it to the xib and be sure to set the
delegate
property).This is my test
TRTrip
class:In the view controller's
viewDidLoad
, I add anMKPointAnnotation
,MKCircle
,TRTrip
, and anMKPolyline
to the map:and this is the
viewForOverlay
method:Here is the result:
The red line on top is the
TRTrip
and the purple one on the bottom is theMKPolyline
.如果您的示例比这更复杂,请检查
代码中是否有任何类似以下的调用:
If your example is a bit more complex then this, check if you have any calls like this:
in the code.