I need a simple MKCircle overlay implementation

I have a small map in my opinion that I want to impose an MKCircle overlay. I have all the coordinates and radius, as I create regions for monitoring. I would like to display this area to the user so that they know what the boundaries are.

In my life there is not a single good textbook on the Internet that will give me just the necessary things to throw a circle on my map and do it.

As a predecessor ... I used Apple examples with no luck. The example of the Regions is supposed to be one of the needs, but all I can do is reset the pin, without a circle. I even copied their classes directly into my project ... no joy. Therefore, if you can point me to a good example or layout, what exactly should be implemented in a simple ViewController, I would be very grateful.

+4
source share
2 answers

My guess is why using the sample code did not work: you did not connect your view controller as a map view delegate. The first step for this is to make sure that the controller implements the MKMapViewDelegate protocol, like this (in its header file):

#import <MapKit/MapKit.h> @interface MyViewController : UIViewController <MKMapViewDelegate> 

If you are creating a view controller from XIB, drag the Ctrl image from the map view onto the instance of your controller and connect it as a view on the delegate map. If you configure it in code, then call theMapView.delegate = self; in -loadView or -viewDidLoad .

Then, at some point (e.g. in -viewDidLoad ),

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

... will result in a view display calling its delegate method -mapView:viewForOverlay: 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]; } 
+15
source

it

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

for the full delegate method, see the full answer for people completely lost, like me.

+4
source

Source: https://habr.com/ru/post/1369094/


All Articles