Swift 使用 GMS 设置地图样式
Swift Map styling with GMS
我在当前项目中使用 GMS
(Google Maps SDK),它看起来像这样
是否可以将地图 style
变成这样的东西?并且仍然使用 GMS
。
您必须使用 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)
}
}
图块可以来自带有 http 请求的服务器,也可以来自您的包。
基本上,图块是一张图像,它在 x
- z
处显示了一张带有 zoom
.
的地图
用法:
let layer = TestTileLayer()
layer.map = mapView
您可以在此处按照自己的方式自定义地图:https://mapstyle.withgoogle.com/
完成自定义后,复制 json 并将其添加到您的项目文件中 style.json
然后将此样式指定给您的地图:
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)")
}
我在当前项目中使用 GMS
(Google Maps SDK),它看起来像这样
是否可以将地图 style
变成这样的东西?并且仍然使用 GMS
。
您必须使用 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)
}
}
图块可以来自带有 http 请求的服务器,也可以来自您的包。
基本上,图块是一张图像,它在 x
- z
处显示了一张带有 zoom
.
用法:
let layer = TestTileLayer()
layer.map = mapView
您可以在此处按照自己的方式自定义地图:https://mapstyle.withgoogle.com/
完成自定义后,复制 json 并将其添加到您的项目文件中 style.json
然后将此样式指定给您的地图:
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)")
}