开发者

KMLViewer Question

开发者 https://www.devze.com 2023-03-04 07:27 出处:网络
This is my first post and I am admittedly over my head, but I do need some help. I downloaded Apple\'s KMLViewer example to look at overlays in maps. After getting it to work, as part of my \"investi

This is my first post and I am admittedly over my head, but I do need some help.

I downloaded Apple's KMLViewer example to look at overlays in maps. After getting it to work, as part of my "investigation," I then added the line

map = [[MKMapView alloc] initWithFrame:self.view.frame];

right after the line

[super viewDidLoad];

I know I didn't have too, but I had another project that required programmatically creating a MKMapView 开发者_如何学JAVAand I wanted to verify the approach on a simpler, working program.

The result was the KMLViewer compiled and executed with no errors, but no longer showed the overlays created by the kml files. If the line was removed, the overlays showed up again.

What am I missing?

Thanks in advance for any help.


The map variable in KMLViewer is declared as an IBOutlet and is connected to the MKMapView in the xib. By re-creating it, the new instance is no longer connected to the one in the xib.

The overlays are probably not showing because:

  • the delegate on the new instance is not set (so viewForOverlay, etc. won't get called)
  • the new map isn't added as a subview

So if you added the following two lines after the alloc+init, it should start working again:

map.delegate = self;
[self.view addSubview:map];

However, the MKMapView in the xib will still be there underneath the new map instance.

0

精彩评论

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

关注公众号