MkMapView cancel download google-plates

I have a case where I need to import an overlap map on top of MkMapView. The overlay completely covers google snippets below, so there is no need to download, and also adds overhead for the application.

Is there any way to tell mkMapView to stop loading fragments?

Thanks for the advanced.

+4
source share
3 answers

There are actually two ways to implement the real "Hide Google Tiles" method (the johndope solution only overlays it but does not prevent the tiles from loading).

Beware that the option described below may reject your application, and option 2 will not, but a little more complicated.

General Part: Retrieving an MKMapTileView

Inside each MKMapView lies an undocumented class like: MKMapTileView . An extraction is not a cause of failure. In this code, the MKMapView instance will be called mapView

 UIView* scrollview = [[[[mapView subviews] objectAtIndex:0] subviews] objectAtIndex:0]; UIView* mkTiles = [[scrollview subviews] objectAtIndex:0]; // <- MKMapTileView instance 

Option 1: Undocumented method (may be a reason for rejection!)

 if ( [mkTiles respondsToSelector:@selector(setDrawingEnabled:)]) [mkTiles performSelector:@selector(setDrawingEnabled:) withObject:(id)NO]; 

This will prevent calling the undocumented setDrawingEnabled method on the setDrawingEnabled instance.

Option 2: Swizzling Method

Outside of your controller implementation, you will write the following:

 // Import runtime.h to unleash the power of objective C #import <objc/runtime.h> // this will hold the old drawLayer:inContext: implementation static void (*_origDrawLayerInContext)(id, SEL, CALayer*, CGContextRef); // this will override the drawLayer:inContext: method static void OverrideDrawLayerInContext(UIView *self, SEL _cmd, CALayer *layer, CGContextRef context) { // uncommenting this next line will still perform the old behavior //_origDrawLayerInContext(self, _cmd, layer, context); // change colors if needed so that you don't have a black background layer.backgroundColor = RGB(35, 160, 211).CGColor; CGContextSetRGBFillColor(context, 35/255.0f, 160/255.0f, 211/255.0f, 1.0f); CGContextFillRect(context, layer.bounds); } 

And somewhere in your code (as soon as your map view is loaded!):

 // Retrieve original method object Method origMethod = class_getInstanceMethod([mkTiles class], @selector(drawLayer:inContext:)); // from this method, retrieve its implementation (actual work done) _origDrawLayerInContext = (void *)method_getImplementation(origMethod); // override this method with the one you created if(!class_addMethod([mkTiles class], @selector(drawLayer:inContext:), (IMP)OverrideDrawLayerInContext, method_getTypeEncoding(origMethod))) { method_setImplementation(origMethod, (IMP)OverrideDrawLayerInContext); } 

Hope this helps anyone, this code was originally described in this post.

+4
source

As far as I know, you cannot prevent MKMapView from loading fragments of Google Maps, and there is a chance that your application will be rejected if it closes the Google logo when MKMapView is displayed - you can consider writing a custom UIScrollView to display your map.

+1
source

I ran into a related issue, but in my case, my overlay did not cover all fragments of Google. If someone has this problem and you are trying to stop the loading of Google snippets, I managed to overlay one overlay on a gray tile (256x256) over the tiles of a Google map. To do this, the top-level tile should be / FakeTiles / 1/1 / 0.png and add this directory to the resources for the project. (NB do not drag this into the project> Add files> Folders> Create folder links for any folders)

 //hack to overlay grey tiles NSString *fakeTileDirectory = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"FakeTiles"]; TileOverlay *greyOverlay = [[TileOverlay alloc] initWithTileDirectory:fakeTileDirectory]; [mapView addOverlay:greyOverlay]; [greyOverlay release]; 

then add a custom trim overlay.

Then you will need this code to scale the gray tile. Calculate the tiles to display in MapRect at "increased magnification" outside the set of overlay tiles

+1
source

Source: https://habr.com/ru/post/1343847/


All Articles