我需要 MKCircle 覆盖的一个非常简单的实现
我的视图上有一张小地图,我想将 MKCircle 叠加放到上面。当我创建监视区域时,我拥有所有坐标和半径。我想向用户显示该区域,以便他们知道边界是什么。
对于我的一生来说,互联网上没有一个好的教程可以为我提供最基本的必要条件,让我在地图上画一个圆圈并完成。
作为先驱......我使用了苹果公司的例子,但没有运气。区域示例应该是唯一需要的,但我所能做的就是放下图钉,没有圆圈。我什至直接将他们的课程复制到我的项目中......没有乐趣。因此,如果您能给我提供一个很好的示例,或者准确地布局需要在简单的 ViewController 中实现的内容,我将非常感激。
I have a small map on my view that I want to drop an MKCircle overlay onto. I have all the coords and radius as I am creating regions for monitoring. I would like to display this region back to the user so they will know what the boundaries are.
For the life of me, there isn't one good tutorial on the internet that will give me just the bare necessities to drop a circle onto my map and be done.
As a precursor... I have used Apple's examples with no luck. The Regions example is supposed to be the one need, but all I can get it to do is drop the pin, no circle. I even copied their classes directly into my project... no joy. So if you can either point me to a good example or layout exactly what needs to be implemented in a simple ViewController, I would be very grateful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜测为什么使用示例代码不起作用:您没有将视图控制器连接为地图视图的委托。这样做的第一步是确保控制器实现 MKMapViewDelegate 协议,如下所示(在其头文件中):
如果您要从 XIB 设置视图控制器,请按住 Ctrl 键从地图视图拖动到控制器实例并连接它作为地图视图的
delegate
出口。如果您在代码中进行设置,请在-loadView
或-viewDidLoad
中调用theMapView.delegate = self;
。然后,在某个时刻(例如,在您的
-viewDidLoad
中),...将导致地图视图调用其委托的
-mapView:viewForOverlay:
方法,您可以实现该方法像这样的东西:My guess for why using the sample code didn’t work: you didn’t hook up your view controller as the map view’s delegate. First step for doing that is making sure the controller implements the MKMapViewDelegate protocol, like this (in its header file):
If you’re setting up the view controller from a XIB, Ctrl-drag from the map view to your controller instance and connect it as the map view’s
delegate
outlet. If you’re setting it up in code, then calltheMapView.delegate = self;
in your-loadView
or-viewDidLoad
.Then, at some point (in your
-viewDidLoad
, for instance),…will result in the map view calling its delegate’s
-mapView:viewForOverlay:
method, which you can implement something like this:对于完整的委托方法,请
参阅 完整的为像我这样完全迷失的人回答。
It's
for the full delegate method, see a complete answer for people completely lost like myself.