繁体   English   中英

Google API地图未显示在TabBar应用程序中

[英]Google API Maps don't show up on TabBar Application

我正在学习Google Maps,它可以在SingleView应用程序中完美运行。 但是我想改进我的应用程序,并使用了“标签栏”菜单。 我将我的ViewController和MapView连接到TabBarController,然后地图加载失败,只有空白正​​方形而不是地图。

我做错了什么?

编辑:

class ViewController: UIViewController, CLLocationManagerDelegate {

@IBOutlet weak var mapView: GMSMapView!

let locationManager = CLLocationManager()

override func viewDidLoad() {

    super.viewDidLoad()
    self.locationManager.requestWhenInUseAuthorization()
    self.locationManager.delegate = self
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
    self.locationManager.startUpdatingLocation()
    self.locationManager.startMonitoringSignificantLocationChanges()    
}

//MARK: Shows Google Map
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

    self.locationManager.stopUpdatingLocation()
    let locationArray = locations as NSArray
    let locationObj = locationArray.lastObject as! CLLocation
    let coord = locationObj.coordinate

    mapView.camera = GMSCameraPosition(target: coord, zoom: 15, bearing: 0, viewingAngle: 0)

    locationManager.stopUpdatingLocation()
}

func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {

    if status == .AuthorizedWhenInUse {

        locationManager.startUpdatingLocation()

        mapView.myLocationEnabled = true
        mapView.settings.myLocationButton = true
    }
}

我认为我发现了问题,至少现在一切正常。 所以我感动

mapView.myLocationEnabled = true
mapView.settings.myLocationButton = true

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation])之前locationManager.stopUpdatingLocation()和现在的作品。

但是我确实感觉我的代码很糟糕,它两次使用了stopUpdatingLocation() 就我而言,这意味着该应用程序在获得好评时只会获得一次用户位置吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM