Domanda

I have an array of coordinates and I already know how to add it on a map as annotations. What I'd like to do now is the following:

  1. each annotation should be a red circle (no pins) that represents a fixed radius of 1 Km around the coordinates. That means that if I zoom in or out the map, the circle should adjusts itself to always represent a 1 Km radius;
  2. if two or more circles overlaps, their color intensity should increase. For example, three or four overlapping circles will produce a solid red circle.

That's all. I have no idea where to start with this, so any help will be greatly appreciated.

È stato utile?

Soluzione

For starter you can use below code but you will have to tweak it little to make it of your use:

in .h file confirm to MKMapViewDelegate

@interface MapViewController : UIViewController <MKMapViewDelegate>

Then,

in "viewDidLoad"
CLLocationCoordinate2D center = {X cordinate, Y cordinate};
//--> Add  overlay
MKCircle *mCircle = [MKCircle circleWithCenterCoordinate:center radius:1000]; //set radius    as per your need
[self.mapView addOverlay:mCircle];

Then,

- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
{
   MKCircleView *cirView = [[MKCircleView alloc] initWithOverlay:overlay];
   [cirView setFillColor:[UIColor redColor]];
   [cirView setStrokeColor:[UIColor blackColor]];
   [cirView setAlpha:0.3f];
    return cirView;
}

I think this should get you started.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top