在ios中添加json文件样式的Google Map

JiosDev

我正在尝试从json文件为我的Google地图加载样式。但这给了我一个错误。我在中添加了api的密钥,在上AppDelegate.swift添加了密钥info.plist,但是卡仍然是标准的。

请告诉我我哪里做错了。一种或多种地图样式无法加载。错误

GoogleMapCustomView.swift

import UIKit
import GoogleMaps

class MapView: UIView {

    @IBOutlet var contentView: UIView!

    //MARK: OVerride
    override init(frame: CGRect) {
        super.init(frame: frame)
        commonInit()

    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        commonInit()

    }

    //MARK: Property
    private func commonInit() {
        Bundle.main.loadNibNamed("MapView", owner: self, options: nil)
        setupMap()
        addSubview(contentView)
        contentView.frame = self.bounds

        }
 func setupMap() {
        let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 6.0)
        let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
        mapView.settings.myLocationButton = true

        mapView.delegate = self as! GMSMapViewDelegate
        contentView = mapView

        //style map
        do{
            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("One or more of the map styles failed to load.\(error)")
        }

    }

style.json

[
    {
        "featureType": "road",
         "elementType": "fill",
        "stylers": [
            { "color": "#99FF33" }
        ]
]
Sh_Khan

您的json无效尝试

[
    {
        "featureType": "road",
         "elementType": "fill",
        "stylers": [
            { "color": "#99FF33" }
        ]
    } <<<<<< you miss this 
]

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Google Map主题样式

来自分类Dev

如何在Google Map iOS中添加图钉

来自分类Dev

如何在iOS的Google Map SDK中添加搜索功能?

来自分类Dev

Google Map在iOS中闪烁

来自分类Dev

向ReactJS Google Map添加自定义样式的问题

来自分类Dev

在Google Map Markers中添加文字

来自分类Dev

在freemarker中迭代Map of Map的Map

来自分类Dev

tableView中的Google Map

来自分类Dev

Google Map中的警告

来自分类Dev

JSON数组中的Google Map Pin标题

来自分类Dev

读取LatLngs的csv文件,将其添加到ArrayList中,然后打印到google map片段

来自分类Dev

如何使用javascript将大json文件拆分为多个小块文件以在Google Map中显示

来自分类Dev

Angular Google Map的自定义样式

来自分类Dev

ACF Google Map-更改样式?

来自分类Dev

GMS的Swift Map样式

来自分类Dev

想要向map()中的特定项目添加类或添加字体样式:斜体

来自分类Dev

在 Map CustomView 中添加 onClickListener

来自分类Dev

在framelayout中访问动态添加的Google Map片段

来自分类Dev

如何在Google Map API中添加文本标签

来自分类Dev

如何在此代码中添加Google Map图标?

来自分类Dev

如何在Google Map v3中添加值

来自分类Dev

Android Google Map:在Activity中添加MapFragment时出错

来自分类Dev

Google Map API v3,在单独的文件中移动地图样式

来自分类Dev

Android中的Google Map Directions

来自分类Dev

在Fragment中呼叫Google Map

来自分类Dev

Google Map中的方向链接

来自分类Dev

如何在iOS中的Google Map上保存位置

来自分类Dev

在IOS中从Google Map Place API提取要求信息

来自分类Dev

如何在iOS环境中访问Google Map