I am drawing overlay on map from kml file which i store in my documents directory. i am viewing about 30 to 40 kml file at once with the line color stored itself in the kml. the problem is some of them doesn't display.
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
return [kmlParser viewForOverlay:overlay];
}
above code is from the reference KMLViewer which can be downloaded from here
when i write the below code it works perfectly fine but all the generated kml file draws with the black color
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
MKOverlayPathView *overlayPathView;
if ([overlay isKindOfClass:[MKPolygon class]])
{
overlayPathView = [[MKPolygonView alloc] initWithPolygon:(MKPolygon*)overlay];
overlayPathView.fillColor = [[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0] colorWithAlphaComponent:0.2];
overlayPathView.strokeColor = [[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0] colorWithAlphaComponent:0.7];
overlayPathView.lineWidth = 3;
return overlayPathView;
}
}
Any help would be greatly Appreciable!
Thanks.
boundingMapRect might be the culprit please check the zoom level of map as well as its boundingmaprect property
Related
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;
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;
}
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.
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.
I want to have a MKMapView with an two different overlays.
First, I have an "Image Overlay on the Map" (TileOverlay),
and secondly I want to draw a route as an overlay on the Map.
Everything works fine if I do this stuff in two different projects (One with the image overlay, and the other with the route overlay)
Now, I am wondering how the viewForOverlay delegate function should look like if I merge my projects?
For my Image (tile) overlay i currently looks like this:
- (MKOverlayView *) mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
TileOverlayView *tileView = [[TileOverlayView alloc] initWithOverlay:overlay];
tileView.tileAlpha = 1.0;
return tileView;
}
For my route Overlay it looks like this:
- (MKOverlayView*)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
{
MKPolylineView *polylineView = [[MKPolylineView alloc] initWithPolyline:overlay];
polylineView.lineJoin = kCGLineJoinRound;
polylineView.strokeColor = [[UIColor blueColor] colorWithAlphaComponent:0.4];
return polylineView;
}
Now if i want to "merge" these (into one Project), how should this method look like?
- (MKOverlayView*)mapView:(MKMapView *)mapView viewForOverlay:(id<MKOverlay>)overlay
{
//what comes here?
}
You could deal with this situation by first checking the type of the overlay passed into your mapView:viewForOverlay: method, like this:
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {
if ([overlay isKindOfClass:[MKPolyline class]]) {
MKPolylineView *polylineView = [[MKPolylineView alloc] initWithPolyline:overlay];
polylineView.lineJoin = kCGLineJoinRound;
polylineView.strokeColor = [[UIColor blueColor] colorWithAlphaComponent:0.4];
return polylineView;
} else {
TileOverlayView *tileView = [[TileOverlayView alloc] initWithOverlay:overlay];
tileView.tileAlpha = 1.0;
return tileView;
}