Using Google’s maps with MapKit

I had a problem. Apple’s map satellite data is old. Google’s is new. It would probably be violating either of their agreements, but this is how to replace the MapKit tiles with Google’s:

    NSString *template = @"{x}&y={y}&z={z}";
    MKTileOverlay *overlay = [[MKTileOverlay alloc] initWithURLTemplate:template];
    overlay.canReplaceMapContent = YES;
    [_mapView addOverlay:overlay level:MKOverlayLevelAboveLabels];

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id <MKOverlay>)overlay {
    if([overlay isKindOfClass:[MKTileOverlay class]]) {
        MKTileOverlayRenderer *v = [[MKTileOverlayRenderer alloc] initWithOverlay:overlay];
        return v;