0

I'm new to XCode and Swift first of all.

I'm creating a View Controller where I implement a Google Map using Google Maps SDK for iOS and I want to apply a custom style to it. I create a json with the Styling Wizard, I copy the JSON and create a new plain text file in the project root and paste the JSON into it. Give the filename style.json. I use the above code based in the docs to change the style of the map:

// Create a GMSCameraPosition that tells the map to display the
    // coordinate -33.86,151.20 at zoom level 6.
    let camera = GMSCameraPosition.camera(withLatitude: -33.460332, longitude: -70.662361, zoom: 17.0)
    let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
    mapView.mapType = .normal

    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)")
    }

    self.view = mapView

But I'm receiving the "Unable to find style.json" error in the console and the style is not apply. I don't know what I'm doing wrong? maybe where I put the json is wrong?

enter image description here

Thanks in advance.

FrancoVP
  • 325
  • 3
  • 5
  • 14
  • 2
    Check the target membership: https://stackoverflow.com/questions/10247680/adding-resource-files-to-xcode of the file? – Larme Jan 17 '19 at 14:07
  • Thanks, that works. Now I feel stupid. Maybe I need to study more about Xcode projects – FrancoVP Jan 17 '19 at 14:17

0 Answers0