Giter VIP home page Giter VIP logo

mapkitgooglestyler's Introduction

MapKitGoogleStyler

CI Status Version License Platform

Introduction

MapKitGoogleStyler 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 this in detail can be found here: https://medium.com/@ortizfernandomartin/customize-mapkits-mkmapview-with-google-maps-styling-wizard-a5dcc095e19f#.ss3dencgh

Example

Using this can't be simpler. The code is self explanatory

//
//  ViewController.swift
//  MapKitGoogleStylerExample
//
//  Created by Fernando Ortiz on 2/6/17.
//  Copyright © 2017 Fernando Martín Ortiz. All rights reserved.
//
import UIKit
import MapKit
import MapKitGoogleStyler

class ViewController: UIViewController {

    @IBOutlet weak var mapView: MKMapView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        mapView.delegate = self
        configureTileOverlay()
    }
    
    private func configureTileOverlay() {
        // We first need to have the path of the overlay configuration JSON
        guard let overlayFileURLString = Bundle.main.path(forResource: "overlay", ofType: "json") else {
                return
        }
        let overlayFileURL = URL(fileURLWithPath: overlayFileURLString)
        
        // After that, you can create the tile overlay using MapKitGoogleStyler
        guard let tileOverlay = try? MapKitGoogleStyler.buildOverlay(with: overlayFileURL) else {
            return
        }
        
        // And finally add it to your MKMapView
        mapView.add(tileOverlay)
    }
    
}

extension ViewController: MKMapViewDelegate {
    func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
        // This is the final step. This code can be copied and pasted into your project
        // without thinking on it so much. It simply instantiates a MKTileOverlayRenderer
        // for displaying the tile overlay.
        if let tileOverlay = overlay as? MKTileOverlay {
            return MKTileOverlayRenderer(tileOverlay: tileOverlay)
        } else {
            return MKOverlayRenderer(overlay: overlay)
        }
    }
}

Requirements

  • Swift 3
  • MapKit, of course

Installation

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

pod "MapKitGoogleStyler"

Author

fmo91, [email protected]

License

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

mapkitgooglestyler's People

Contributors

fmo91 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mapkitgooglestyler's Issues

MapKitGoogleStyler no longer working

Can anyone confirm that this library is no longer functioning -- perhaps Apple restricted usage of tileOverlays for this purpose.

I call the following in viewDidLoad

//  LayoutManager is a custom library that I wrote, it successfully places the MapView onscreen
        mapView = MKMapView(frame: LayoutManager.between(elementAbove: roundName, elementBelow: selectTeamButton, width: view.frame.width, topPadding: 2 * .MARGINAL_PADDING, bottomPadding: .PADDING))
        mapView.delegate = self
        mapView.showsUserLocation = true
        mapView.setUserTrackingMode(.follow, animated: true)
        view.addSubview(mapView)
        restyleMap()

Where restyleMap contains

guard let overlayFileURLString = Bundle.main.path(forResource: "overlay", ofType: "json") else {
            return
        }
        let overlayFileURL = URL(fileURLWithPath: overlayFileURLString)
        debugPrint(overlayFileURL)
        // After that, you can create the tile overlay using MapKitGoogleStyler
        guard let tileOverlay = try? MapKitGoogleStyler.buildOverlay(with: overlayFileURL) else {
            return
        }
        // And finally add it to your MKMapView
        mapView.delegate = self
        mapView.addOverlay(tileOverlay, level: .aboveLabels)
        debugPrint(mapView.overlays)

I can confirm that the overlay is added to the map, but the dark style JSON doesn't load. I put a breakpoint inside the func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer function, but the function isn't getting called.

Any thoughts on why this might be happening? Is the renderer returned without the necessary attributes to make the map load it?

Swift 4 display issues

When using the pod with swift 4, it's only roads and parks that gets the Google Maps overlay, buildings are set to default apple style

how to change satellite hybrid etc.?

after applying style i am not able to get mapView.maptype = .hybrid or .satellite
it displays same styled map not satellite version

what to do?

Swift 4

I'm trying to implement this in Xcode 9.0 beta using Swift 4. It doesn't seem to work. No warnings or errors, I'm just getting empty map with no tiles. Do you know if your pod still works?

Change font size

First of all thanks for your great work!

I am using your work in one of my projects but somehow the label's font size seems too be very small. Do you know a way to fix this?

Best regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.