gpt4 book ai didi

swift - Google API map 未显示在 TabBar 应用程序上

转载 作者:行者123 更新时间:2023-11-30 13:54:08 25 4
gpt4 key购买 nike

我正在学习 Google map ,它在 SingleView 应用程序中完美运行。不过,我想改进我的应用程序并使用了选项卡栏菜单。我将 ViewController 与 MapView 连接到 TabBarController,然后 map 无法加载,只有空白方 block 而不是 map 。

我做错了什么?

编辑:

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

locationManager.stopUpdatingLocation()之前调用func locationManager(manager: CLLocationManager, didUpdateLocationslocations: [CLLocation]),现在它可以工作了。

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

关于swift - Google API map 未显示在 TabBar 应用程序上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33872856/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com