想要更改谷歌地图的背景

时间:2017-09-08 05:46:55

标签: ios objective-c swift google-maps

我想将背景更改为谷歌地图的白色,但我无法更改它。所以,任何人都知道任何细节,请提供给我。如果有可能,请给我一个提示或代码。另外,给我一个适当的建议。

2 个答案:

答案 0 :(得分:3)

你可以这样做:

import UIKit
import GoogleMaps

let kMapStyle = "[" +
"  {" +
"    \"featureType\": \"poi.business\"," +
"    \"elementType\": \"all\"," +
"    \"stylers\": [" +
"      {" +
"        \"visibility\": \"off\"" +
"      }" +
"    ]" +
"  }," +
"  {" +
"    \"featureType\": \"transit\"," +
"    \"elementType\": \"labels.icon\"," +
"    \"stylers\": [" +
"      {" +
"        \"visibility\": \"off\"" +
"      }" +
"    ]" +
"  }" +
"]"
class ViewController: UIViewController {

  // Set the status bar style to complement night-mode.
  override var preferredStatusBarStyle: UIStatusBarStyle {
    return .lightContent
  }

  override func loadView() {
    let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 14.0)
    let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)

    do {
      // Set the map style by passing a valid JSON string.
      mapView.mapStyle = try GMSMapStyle(jsonString: kMapStyle)
    } catch {
      NSLog("One or more of the map styles failed to load. \(error)")
    }

    self.view = mapView
  }
}

答案 1 :(得分:0)

在这里创建自定义样式...

https://mapstyle.withgoogle.com/

  • 创建您的风格并点击完成
  • 您将获得json格式文本并将其粘贴到您的代码中。

您可以参考@Dhiraj Kumar的答案,了解代码的粘贴位置。