谷歌地图与标签栏控制器冲突

时间:2019-07-02 18:32:19

标签: swift uitabbarcontroller google-maps-sdk-ios

我需要通过标签栏控制器嵌入Google地图,但是我遇到了问题。如果我未在控制器选项卡栏的第一个屏幕上显示google maps,则不会执行确定地理位置访问和确定当前位置的功能:

func locationManager (_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus)
func locationManager (_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])

注释1: 具有选项卡栏控制器的应用程序仅在首次启动时才能正常工作,如果我杀死了该应用程序,然后将其打开,则地理定位功能将不起作用。它仅有助于重新安装应用程序

注释2: Google卡仅在标签栏控制器中不起作用。我分别进行了操作,或初始化了第一个视图。但是我需要它们完全位于选项卡栏控制器中

注释3: 这里显示的是一个故事板,viewcontroller 3包含Google地图

https://cdn1.savepice.ru/uploads/2019/7/2/b82c92582c21b4a208590b226e5dc2b9-full.png

class ViewController: UIViewController {

 @IBOutlet weak
 var mapView: GMSMapView!

  let locationManager = CLLocationManager()

 override func viewDidLoad() {
  super.viewDidLoad()
  locationManager.delegate = self
  locationManager.requestWhenInUseAuthorization()
  mapView.delegate = self
 }
}

extension ViewController: CLLocationManagerDelegate {
 func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
  if status == .authorizedWhenInUse {
   locationManager.startUpdatingLocation()
   mapView.isMyLocationEnabled = true
   mapView.settings.myLocationButton = true
  } else {
   let camera = GMSMutableCameraPosition(latitude: 48.706986, longitude: 44.515993, zoom: 15)
   mapView.camera = camera
  }
 }
 func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
  if let location = locations.first {
   mapView.camera = GMSCameraPosition(target: location.coordinate, zoom: 15, bearing: 0, viewingAngle: 0)
   locationManager.stopUpdatingLocation()
  }
 }
}

0 个答案:

没有答案