How to reduce the thickness of MKOverlay circle? - ios

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;

Related

How to Draw the border color for the PolyLine

I need to draw the border for the Polyline on my Mapview
Here is the screenshot that I need to implement but I am getting the poly line without the border.
Code Work:
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay {
MKPolylineRenderer *renderer = [[MKPolylineRenderer alloc] initWithPolyline:overlay];
renderer.strokeColor = [UIColor rle_lightBurGundy];
renderer.fillColor = [UIColor rle_whiteColor];
renderer.lineWidth = 4.0;
return renderer;
}
Check out this thread Draw MKPolyline Fill Color. Chandni - Systematix' s answer is a good way to solve your issue ... you need to make an custom renderer that will draw 2 paths (the border and the main polyline). He linked a github exemple you can check the ASPolylineRenderer.h/.m
Github link : https://github.com/nighthawk/ASPolylineView

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.

Why MKCircle is not displayed on MKMapView iOS8

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.

adding multiple circles around a pin in iOS

How can I add and display multiple circles in different colors inside a map (MKMapView)? I figured out how to add one circle, but can't figure out how to add multiple circles in various sizes and colors ... any help would be appreciated!
Here's some code I use to draw two concentric circles at a given location on the map. The outer one is gray, and the inner one is white. (in my example "range" is the circle radius) Both have some transparency:
- (void)drawRangeRings: (CLLocationCoordinate2D) where {
// first, I clear out any previous overlays:
[mapView removeOverlays: [mapView overlays]];
float range = [self.rangeCalc currentRange] / MILES_PER_METER;
MKCircle* outerCircle = [MKCircle circleWithCenterCoordinate: where radius: range];
outerCircle.title = #"Stretch Range";
MKCircle* innerCircle = [MKCircle circleWithCenterCoordinate: where radius: (range / 1.425f)];
innerCircle.title = #"Safe Range";
[mapView addOverlay: outerCircle];
[mapView addOverlay: innerCircle];
}
Then, make sure your class implements the MKMapViewDelegate protocol, and define how your overlays look in the following method:
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {
MKCircle* circle = overlay;
MKCircleView* circleView = [[MKCircleView alloc] initWithCircle: circle];
if ([circle.title compare: #"Safe Range"] == NSOrderedSame) {
circleView.fillColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.25];
circleView.strokeColor = [UIColor whiteColor];
} else {
circleView.fillColor = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.25];
circleView.strokeColor = [UIColor grayColor];
}
circleView.lineWidth = 2.0;
return circleView;
}
And, of course, don't forget to set the delegate on your MKMapView object, or the above method will never get called:
mapView.delegate = self;

Resources