开发者

I need a dead simple implementation of MKCircle overlay

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 intern开发者_StackOverflow社区et 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.


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):

#import <MapKit/MapKit.h>

@interface MyViewController : UIViewController <MKMapViewDelegate>

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 call theMapView.delegate = self; in your -loadView or -viewDidLoad.

Then, at some point (in your -viewDidLoad, for instance),

[theMapView addOverlay:[MKCircle circleWithCenterCoordinate:someCoordinate radius:someRadius]];

…will result in the map view calling its delegate’s -mapView:viewForOverlay: method, which you can implement something like this:

-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {
    MKCircleView *circleView = [[MKCircleView alloc] initWithCircle:(MKCircle *)overlay];
    circleView.fillColor = [UIColor blueColor];
    return [circleView autorelease];
}


It's

-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <
MKOverlay>)overlay

for the full delegate method, see a complete answer for people completely lost like myself.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜