Why MKCircle is not displayed on MKMapView iOS8 - ios

I create new overlays like this:
MKCircle *circle = [MKCircle circleWithCenterCoordinate:region.coordinate radius:region.radius];
[self.mapView addOverlay:circle];
also I implemented delegate method:
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {
MKCircleRenderer *circleRenderer = [[MKCircleRenderer alloc] init];
circleRenderer.fillColor = [UIColor greenColor];
circleRenderer.alpha = 1.f;
return circleRenderer;
}
both parts of code are called, mapView != nil at that moment, it's delegate set,
but I cannot see the circle on my map.
What am I doing wrong?

As per #Rob suggestion you need to init MKCircleRenderer using other method initWithCircle.
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay {
MKCircleRenderer *circleRenderer = [[MKCircleRenderer alloc] initWithCircle:overlay];
circleRenderer.fillColor = [UIColor greenColor];
circleRenderer.alpha = 1.f;
return circleRenderer;
}
Also make sure that fence distance is proper enough to visible the circle in map.
For example:
CLLocationDistance fenceDistance = 100000;
MKCircle *circle = [MKCircle circleWithCenterCoordinate:region.coordinate radius:fenceDistance];
[self.mapView addOverlay:circle];

Rather than init, call the MKCircleRenderer method initWithCircle.
Obviously, make sure the delegate of the map view is set, that your code that adds the overlay and that instantiates the renderer is called at all, etc., but initWithCircle is the likely culprit.

Related

How to reduce the thickness of MKOverlay circle?

I have added a circle to MKMapView using below code in delegate function:
-(MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay{
MKCircleRenderer *circleView = [[MKCircleRenderer alloc] initWithOverlay:overlay];
circleView.strokeColor = [UIColor blueColor];
return circleView;
}
I want to reduce the thickness, can anyone help?
I found a solution for it, there is a property for increase/decrease line width in MKCircleRenderer class itself:
circleView.lineWidth = 2;

How to create a circle overlay over my annotation in Maps using MApkit in iOS?

I want to create a circle overlay over the annotation. I'm using swift 3.0. Any help is appreciated !!
Try a custom overlay. Add this in viewDidLoad:
MKCircle *circle = [MKCircle circleWithCenterCoordinate:userLocation.coordinate radius:1000];
[map addOverlay:circle];
userLocation can be obtained by storing the MKUserLocationAnnotation as a property. Then, to actually draw the circle, put this in the map view's delegate:
- (MKOverlayRenderer *)mapView:(MKMapView *)map viewForOverlay:(id <MKOverlay>)overlay
{
MKCircleRenderer *circleView = [[MKCircleRenderer alloc] initWithOverlay:overlay];
circleView.strokeColor = [UIColor redColor];
circleView.fillColor = [[UIColor redColor] colorWithAlphaComponent:0.4];
return circleView;
}

How to make stretchable circular region around pin like Reminder App

I tried following code to make circle:
MKCircle *circle = [MKCircle
circleWithCenterCoordinate:userLocation.coordinate radius:1000];
[map addOverlay:circle];
Then in Map View's delegate:
- (MKOverlayView *)mapView:(MKMapView *)map viewForOverlay:(id <MKOverlay>)overlay
{
MKCircleView *circleView = [[MKCircleView alloc] initWithOverlay:overlay];
circleView.strokeColor = [UIColor redColor];
circleView.fillColor = [[UIColor redColor] colorWithAlphaComponent:0.4];
return circleView;
}
It adds a circle around the pin, but how to make the circle stretchable like Reminder App's Location Reminder feature?
Look what I found:
https://github.com/d0ping/DBMapSelectorViewController
You can set up a lot of things like Radius of the circle, Background and Stroke color and even the Radius text.

MkCircle with MapKit, synchronyse with current user location

I am working in a project with MapKit, and I want to update the location of circle in the center of current user location. I can do that by implementing this methods. The problem is that user location when changes its coordinates animates and the method DidUpdateUserLocation doesnt get called everytime.
What I want to do is smoothly changing position with these methods faster and animating the circle like user location (blue dot) changes (dispatch wont do any of this tasks faster)
-(void)viewDidLoad
{
[super viewDidLoad];
[self UpdateCirclePosition];
}
This method get executed when user location changes.
- (void)mapView:(MKMapView *)mv didUpdateUserLocation:(MKUserLocation *)userLocation1
{
[self UpdateCirclePosition];
}
This method is to set new coordinates for the circle
-(void)UpdateCirclePosition
{
//Removing past layouts from MapView
[self.mapView removeOverlays: [self.mapView overlays]];
//Set the circle in the middle of the current user location
MKCircle *circle = [MKCircle circleWithCenterCoordinate:locationManager.location.coordinate radius:10];
[self.mapView addOverlay:circle];
}
And this is the method when overlay changes
- (MKOverlayView *)mapView:(MKMapView *)map viewForOverlay:(id <MKOverlay>)overlay
{
MKCircleView *circleView = [[MKCircleView alloc] initWithOverlay:overlay];
circleView.strokeColor = [UIColor redColor];
if (something)
{
circleView.fillColor = [[UIColor greenColor] colorWithAlphaComponent:0.2];
}
else
{
circleView.fillColor = [[UIColor redColor] colorWithAlphaComponent:0.2];
}
circleView.lineWidth = 0.5;
return circleView;
}
didUpdateUserLocation gets the latest position, but then you ignore it and call UpdateCirclePosition. You should pass the coordinates from userLocation1 into UpdateCirclePosition and use them to reposition your circle.

How to create Text Overlay in an MKCircle (iOS MapKit Overlays)

I have searched far and wide for a proper solution but have yet to find any.
-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay
{
MKCircleView* circleView = [[[MKCircleView alloc] initWithOverlay:overlay] autorelease];
circleView.fillColor=[UIColor redColor];
return circleView;
}
-(void)overlay{
MKCircle *circleOverlay;
CLLocationCoordinate2D coords = CLLocationCoordinate2DMake(1.303819,103.7689956); //giza
circleOverlay=[MKCircle circleWithCenterCoordinate:coords radius:200];
[self.mapView addOverlay:circleOverlay];
}
Is there a simple way to add a text into this circle?

Resources