How to erase iOS6 maps in MapKit

Update: be aware as this is not working on iOS7, however in iOS7 MapKit officially supports to disable base layer !

This blog : https://blog.sumbera.com/2011/09/18/how-to-disable-base-google-maps-in-mapkit/ wrote about how to disable Google maps in MapKit. Now with new iOS6 and brand new Apple maps and OpenGL rendering , the question is how to disable rendering of the base maps without using undocumented functions. Removing whole base layer (VKMapView) is possible but cripples touch handling of the overlays. So here is very simple way how to do this without removing VKMapView – just set opacity of the layer to 0.0. This will erase base iOS6 maps .

+(void) eraseiOS6maps:(UIView*) mapView{
   // -- get rendering layer
    UIView *rootView = [mapView.subviews objectAtIndex:0];
    UIView *vkmapView = [rootView.subviews objectAtIndex:0];
    UIView *vkmapCanvas = [vkmapView.subviews objectAtIndex:0];
   // -- set opacity to 0.0 
    [vkmapCanvas.layer setOpacity:0.0];
}

View hierarchy:

MkMapView/UIView/VKMapView/VKMapCanvas
MkMapView/UIView/MkScrollContainerView/MkOverlayContainerView/MkOverlayClusterView/<your overlay>
MkMapView/UIView/MkAnnotation/...
MkMapView/MkAttributionLabel
This entry was posted in Code, MapKit, Objective-C. Bookmark the permalink.

4 Responses to How to erase iOS6 maps in MapKit

  1. Pingback: How to disable base Google Maps in MapKit « Geospatial Haiku

  2. Billy says:

    Do you know how to add a Tiled WMS overlay in MapKit? I have wms that update every three hours and would not be able to cache them.

  3. noxymoelge says:

    Hi Stanislav! I am so happy I ‘accidentially’ came here from stackoverflow. I actually saw your solution and boy it works. But i have one suggestion to make it work even better – see also here http://pastebin.com/SkGhVmE8 for code, but i will try to put it directly in the comment here:

    - (UIView*) viewToDeactivateInView:(UIView*)view {
        UIView *viewFound = nil;
        if( view && view.subviews && [view.subviews count] > 0 ) {
            for( UIView *currentView in view.subviews ) {
                NSString *className = NSStringFromClass( [currentView class] );
                if( [className isEqualToString:@"VKMapCanvas"] ) {
                    viewFound = currentView;
                    break;
                }
                else {
                    viewFound = [self viewToDeactivateInView:currentView];
                    if( viewFound ) {
                        break;
                    }
                }
            }
        }
        return viewFound;
    }
    
    - (void) baseMapEnableVisibility:(BOOL)isVisible {
        UIView *targetView = [self viewToDeactivateInView:localMapView];
        if( targetView ) {
            NSLog( @"MAP CANVAS: %@", NSStringFromClass([targetView class]) );
            [targetView.layer setOpacity:(isVisible ? 1.0 : 0.0)];
        }
        else {
            NSLog( @"MAP CANVAS NOT FOUND." );
        }
    }
    

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s