作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
当 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
}
最佳答案
您可以尝试使用 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/
我是一名优秀的程序员,十分优秀!