在iOS中使用UISwitch切换Google Maps的isTrafficEnabled参数

问题描述

嗨,我是iOS开发的新手,正在开发一个使用Google Maps API的简单应用程序。我正在尝试添加一项功能用户可以禁用 isTrafficEnabled 属性。我试图通过切换UISwitch按钮将其关闭。但是,尽管该开关可以正常工作,这意味着在协议的帮助下它可以在不同的视图中显示是非(我可以在切换时在控制台上显示是非),但流量不会从Google Maps中消失。

在viewDidLoad中调用函数

createGoogleMaps(showTrafic: true)

在屏幕上创建Google地图的功能

// Mark - Creating google maps
    func createGoogleMaps(showTrafic: Bool){
        camera = GMSCameraPosition.camera(withLatitude: (locationManager.location?.coordinate.latitude)!,longitude: (locationManager.location?.coordinate.longitude)!,zoom: 16)
        mapView = GMSMapView.map(withFrame: self.view.frame,camera: camera!)
        mapView.isTrafficEnabled = showTrafic // for getting traffic data.
        mapView.animate(to: camera!)
        mapView.setMinZoom(10,maxZoom: 20)
        mapView.settings.compassButton = true //
        mapView.isMyLocationEnabled = true // user's location
        mapView.settings.myLocationButton = true //
        mapView.settings.scrollGestures = true
        mapView.settings.zoomGestures = true
        mapView.settings.rotateGestures = true
        mapView.settings.tiltGestures = true
        mapView.isIndoorEnabled = false
        // Mark - Dark mode light mode support
        // think of a way that you can also do the switching of the mode immediately.
        if #available(iOS 13.0,*) {
            switch traitCollection.userInterfaceStyle {
            case .dark:
                styleMapDark()
            default:
                styleMapLight()
            }
            self.view.addSubview(mapView)
        }
    }

ViewController扩展内的功能符合我的自定义协议:

func traficDensity(isShown: Bool) {
        mapView.isTrafficEnabled = isShown
        print("\(isShown)")
    }

(PS。UISwitch按钮位于帐户页面“配置”部分的不同ViewController中。因此,我的问题与UISwitch doesn't work on Google Maps SDK for iOS?不同)

从我的简单“帐户”页面上的

ScreenShot:

enter image description here

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...