Я пытаюсь загрузить собственный стиль в представление карты Google в IOS (swift 5.2.2). Код показан ниже:
override func viewDidLoad() {
super.viewDidLoad()
mapView.settings.compassButton = true
mapView.isMyLocationEnabled = true
mapView.settings.myLocationButton = true
mapView.mapType = .normal
do{
if let styleURL = Bundle.main.url(forResource: "style", withExtension:"json"){
mapView.mapStyle = try GMSMapStyle(contentsOfFileURL: styleURL)
NSLog("fstyle loaded")
}else
{
NSLog("file not found")
}
}
catch{
NSLog("failed to load style")
}
}
У меня есть файл json, который отлично работает в Android. В примере используется следующий файл (но также и с другими, более простыми файлами, результат тот же):
[
{
"featureType": "landscape",
"elementType": "all",
"stylers": [
{
"hue": "#FFBB00"
},
{
"saturation": 43.400000000000006
},
{
"lightness": 37.599999999999994
},
{
"gamma": 1
}
]
},
{
"featureType": "landscape",
"elementType": "geometry",
"stylers": [
{
"weight": "0.01"
},
{
"gamma": "3.36"
}
]
},
{
"featureType": "landscape",
"elementType": "geometry.fill",
"stylers": [
{
"hue": "#0039ff"
},
{
"gamma": "1.01"
},
{
"lightness": "-4"
}
]
},
{
"featureType": "landscape.natural",
"elementType": "geometry",
"stylers": [
{
"visibility": "on"
},
{
"gamma": "2.27"
}
]
},
{
"featureType": "landscape.natural.landcover",
"elementType": "labels",
"stylers": [
{
"color": "#251111"
}
]
},
{
"featureType": "poi",
"elementType": "all",
"stylers": [
{
"hue": "#00FF6A"
},
{
"saturation": -1.0989010989011234
},
{
"lightness": 11.200000000000017
},
{
"gamma": 1
}
]
},
{
"featureType": "poi",
"elementType": "geometry",
"stylers": [
{
"visibility": "on"
}
]
},
{
"featureType": "poi",
"elementType": "labels",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "poi",
"elementType": "labels.text",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "poi.park",
"elementType": "geometry",
"stylers": [
{
"color": "#06dc8c"
}
]
},
{
"featureType": "road.highway",
"elementType": "all",
"stylers": [
{
"hue": "#FFC200"
},
{
"saturation": -61.8
},
{
"lightness": 45.599999999999994
},
{
"gamma": 1
}
]
},
{
"featureType": "road.arterial",
"elementType": "all",
"stylers": [
{
"hue": "#FF0300"
},
{
"saturation": -100
},
{
"lightness": 51.19999999999999
},
{
"gamma": 1
}
]
},
{
"featureType": "road.arterial",
"elementType": "labels",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "road.local",
"elementType": "all",
"stylers": [
{
"hue": "#FF0300"
},
{
"saturation": -100
},
{
"lightness": 52
},
{
"gamma": 1
}
]
},
{
"featureType": "road.local",
"elementType": "labels",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "road.local",
"elementType": "labels.text",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "transit",
"elementType": "geometry",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "transit",
"elementType": "labels",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "transit",
"elementType": "labels.text",
"stylers": [
{
"visibility": "off"
}
]
},
{
"featureType": "water",
"elementType": "all",
"stylers": [
{
"hue": "#0078FF"
},
{
"saturation": -13.200000000000003
},
{
"lightness": 2.4000000000000057
},
{
"gamma": 1
}
]
},
{
"featureType": "water",
"elementType": "labels",
"stylers": [
{
"visibility": "off"
}
]
}
]
Результат такой, как показано на этой картинке
Также нет ошибок в логах, кажется, что стиль действительно загружен.