https://github.com/fmo91/mapkitgooglestyler
Customize iOS MapKit using Google JSON styles
https://github.com/fmo91/mapkitgooglestyler
google-maps ios mapkit swift
Last synced: 8 months ago
JSON representation
Customize iOS MapKit using Google JSON styles
- Host: GitHub
- URL: https://github.com/fmo91/mapkitgooglestyler
- Owner: fmo91
- License: mit
- Created: 2017-02-01T17:29:29.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-05-11T18:03:33.000Z (almost 5 years ago)
- Last Synced: 2024-10-11T21:45:48.098Z (over 1 year ago)
- Topics: google-maps, ios, mapkit, swift
- Language: Swift
- Size: 42 KB
- Stars: 132
- Watchers: 9
- Forks: 41
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MapKitGoogleStyler
[](https://travis-ci.org/fmo91/MapKitGoogleStyler)
[](http://cocoapods.org/pods/MapKitGoogleStyler)
[](http://cocoapods.org/pods/MapKitGoogleStyler)
[](http://cocoapods.org/pods/MapKitGoogleStyler)
## Introduction
MapKitGoogleStyler allows you to include Google Maps JSON styles, that you can create [here](https://mapstyle.withgoogle.com/), 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
```swift
//
// 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](http://cocoapods.org). To install
it, simply add the following line to your Podfile:
```ruby
pod "MapKitGoogleStyler"
```
## Author
fmo91, ortizfernandomartin@gmail.com
## License
MapKitGoogleStyler is available under the MIT license. See the LICENSE file for more info.