gpt4 book ai didi

ios - swift - 如何在应用程序运行时顺利加载谷歌地图 View

转载 作者:搜寻专家 更新时间:2023-11-01 05:37:41 25 4
gpt4 key购买 nike

当 View 在初始启动时加载(点击图标/运行程序),谷歌地图 View 在英国启动,然后以非常突然的方式传送到我当前的位置。我的代码中没有任何我认为会导致它加载到那里然后传送到我的位置的英国坐标。

如何解决这个问题并使启动过程更优雅?

let locationManager = CLLocationManager()
let googleMapView: GMSMapView!

override func viewDidLoad() {
super.viewDidLoad()

self.locationManager.requestAlwaysAuthorization()
self.locationManager.requestWhenInUseAuthorization()

if CLLocationManager.locationServicesEnabled() {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startMonitoringSignificantLocationChanges()

}

}

override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)

self.googleMapView = GMSMapView(frame: self.mapViewContainer.frame)
self.view.addSubview(self.googleMapView)
self.googleMapView.myLocationEnabled = true
self.googleMapView.settings.compassButton = true

}

Beginning of Launch

Abruptly shifts to current location

最佳答案

您可以尝试使用 Map Objects .默认情况下, map 上不显示位置数据。您可以通过在 GMSMapView 上设置 myLocationEnabled 来启用蓝色的“我的位置”点和罗盘方向。

mapView.myLocationEnabled = true

启用此功能还将通过 myLocation 属性提供用户的当前位置。

if let mylocation = mapView.myLocation {
print("User's location: \(mylocation)")
} else {
print("User's location is unknown")
}

此属性可能不会立即可用 - 例如,如果 iOS 提示用户允许访问此数据。在这种情况下它将为零。

关于ios - swift - 如何在应用程序运行时顺利加载谷歌地图 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34984898/

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