MBMapKitGoogleStyler 0.1.0

MBMapKitGoogleStyler 0.1.0

Maintained by Michael Biggs.



  • By
  • jmbiggs

MBMapKitGoogleStyler

CI Status Version License Platform

Introduction

NOTE: This is an Objective-C port of MapKitGoogleStyler by fmo91. Use it if you are unable (or unwilling) to use Swift in your project, otherwise you can use the original.

MBMapKitGoogleStyler allows you to include Google Maps JSON styles, that you can create here, and customize your MKMapView to look just like you want (or your client). Including this library is very very easy.

A post explaining the concept in detail (and how to use the Swift version) can be found here: https://medium.com/@ortizfernandomartin/customize-mapkits-mkmapview-with-google-maps-styling-wizard-a5dcc095e19f#.ss3dencgh

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

To easily get styling on an MKMapView:

  1. Create your styling here, and generate a JSON file.

  2. Put the JSON in a plain text file in your project. You can name it whatever you want, in this example I'll call it 'MapStyle.json'.

  3. Import MBMapKitGoogleStyler into your view controller

#import <MBMapKitGoogleStyler/MBMapKitGoogleStyler.h>
  1. Make sure your view controller is a MKMapViewDelegate, and implement -mapViewrendererForOverlay

    Interface declaration:

@interface MBViewController () <MKMapViewDelegate>

Set delegate on MKMapView (in -viewDidLoad):

[_mapView setDelegate:self];

Implement delegate method:

- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay
{
    MKTileOverlay * tileOverlay = (MKTileOverlay*)overlay;
    if (tileOverlay) {
        return [[MKTileOverlayRenderer alloc] initWithTileOverlay:tileOverlay];
    } else {
        return [[MKOverlayRenderer alloc] initWithOverlay:overlay];
    }
}
  1. Write a function to add the tile overlay to your Map View (make sure you import the JSON file as you named it)
- (void)configureTileOverlay {
    // import the JSON file
    NSString * overlayFileURLString = [[NSBundle mainBundle] pathForResource:@"MapStyle" ofType:@"json"];

    NSURL * overlayFileURL = [NSURL fileURLWithPath:overlayFileURLString];
    MKTileOverlay * tileOverlay = [MBMapKitGoogleStyler buildOverlayWithJSONFileURL:overlayFileURL];
    [_mapView addOverlay:tileOverlay];
}

Call it after setting the delegate (-viewDidLoad):

[_mapView setDelegate:self];
[self configureTileOverlay];

Requirements

  • MapKit

Installation

MBMapKitGoogleStyler is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'MBMapKitGoogleStyler'

Author

jmbiggs, [email protected] fmo91, [email protected] (original Swift version)

License

MBMapKitGoogleStyler is available under the MIT license. See the LICENSE file for more info.