Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implement Google Maps Styling Wizard JSON

I customized google map's appearance with Styling Wizard. It told me to copy the JSON, which I did, but I have no idea where to implement it in my iOS Swift project.

Does anyone know where to put it?
Thanks!

like image 280
LinusGeffarth Avatar asked Jan 05 '23 05:01

LinusGeffarth


1 Answers

You can use this piece of code in order to create stylish maps where you have created the GoogleMaps object mapView

Swift 3.x code

do {
        // Set the map style by passing the URL of the local file. Make sure style.json is present in your project
        if let styleURL = Bundle.main.url(forResource: "style", withExtension: "json") {
            mapView.mapStyle = try GMSMapStyle(contentsOfFileURL: styleURL)
        } else {
            print("Unable to find style.json")
        }
    } catch {
        print("The style definition could not be loaded: \(error)")
    }

The link you posted as Styling Wizard will be used to create a json file. Modify your map and create a json. Then copy the json and create a new plain text file and paste the json. Give the file name style.json. Copy the .json file in your project and use the above code to change the style of your map. Check this Link for more details.

See the output of my result. I created a silver map.

enter image description here

like image 180
Rajan Maheshwari Avatar answered Jan 12 '23 16:01

Rajan Maheshwari