Swift Map styling with GMS
Asked Answered
P

2

5

Im using GMS (Google Maps SDK) In my current project, and it looks like this

Is it possible to style the map to something like this? and still use GMS.

Pneumograph answered 3/9, 2016 at 21:51 Comment(0)
P
10

You can customize the map the way you want here: https://mapstyle.withgoogle.com/

Once you are done with customization, copy the json and add it your project in a file say style.json

Then assign this styling to your map as:

do {
            // Set the map style by passing the URL of the local file.
            if let styleURL = Bundle.main.url(forResource: "style", withExtension: "json") {
                mapView.mapStyle = try GMSMapStyle(contentsOfFileURL: styleURL)

            } else {
                NSLog("Unable to find style.json")
            }
        } catch {
            NSLog("One or more of the map styles failed to load. \(error)")
        } 
Puppis answered 9/2, 2017 at 9:33 Comment(0)
M
0

You must use custom tiles:

class TestTileLayer: GMSSyncTileLayer {
 override func tileForX(x: UInt, y: UInt, zoom: UInt) -> UIImage? {
    // On every odd tile, render an image.
    let image = "\(x)-\(y)-\(zoom)"
    return UIImage(named: image)
  }
}

the tiles can come from a server with an http request or from your bundle. Basically a tile is an image which show a piece of map at x - z with a zoom.

usage:

let layer = TestTileLayer()
layer.map = mapView
Manes answered 3/9, 2016 at 21:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.