【发布时间】:2019-11-25 08:54:30
【问题描述】:
我正在使用 CLLocation 来获取商场的当前楼层。
private var currentLocation = CLLocation() {
didSet {
locationLabel.text = "Longitude = \(currentLocation.coordinate.longitude) \nLatitude = \(currentLocation.coordinate.latitude)"
if let level = currentLocation.floor?.level {
floorLabel.text = "Floor = \(level)"
} else {
floorLabel.text = "No floor detected"
}
}
}
extension ViewController: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let currentLocation = locations.first {
self.currentLocation = currentLocation
}
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("locationManager didFailWithError: \(error.localizedDescription)")
}
}
现在,当我运行此代码时,它工作正常,直到我加载谷歌地图。这是代码。
@IBAction func mapInitClicked(_ sender: Any) {
let mapView = GMSMapView(frame: mapContainerView.bounds)
mapView.autoresizesSubviews = true
mapView.autoresizingMask = [.flexibleHeight, .flexibleWidth, .flexibleTopMargin, .flexibleBottomMargin, .flexibleLeftMargin, .flexibleRightMargin]
mapView.settings.compassButton = true
mapView.settings.indoorPicker = false
mapView.isIndoorEnabled = false
mapView.settings.myLocationButton = true
mapView.isBuildingsEnabled = false
//mapView.isMyLocationEnabled = true
//floorLevel = mapView.indoorDisplay.activeLevel?.shortName
if currentLocation.coordinate.latitude == 0.0
{
let newCamera = GMSCameraPosition.camera(withLatitude: 40.7139018, longitude: -74.0156599, zoom: 19.5)
mapView.camera = newCamera
}
else
{
let newCamera = GMSCameraPosition.camera(withLatitude: currentLocation.coordinate.latitude, longitude: currentLocation.coordinate.longitude, zoom: 1.0)
mapView.camera = newCamera
}
mapContainerView.addSubview(mapView)
}
一加载 Google 地图,我就开始从 CLLocation 获取发言权为 Nil。下面的代码行开始执行。
floorLabel.text = "No floor detected"
有谁知道它出了什么问题?
【问题讨论】:
-
对这个社区没有一个评论/答案?很奇怪。
-
在哪里调用API来更新位置?
-
@vadian,只要用户移动设备,位置就会自动更新。
-
那位置管理器好像没有检测到楼层。
-
不,它会在我加载 Google 地图之前检测到地板。一旦地图加载并显示在屏幕上,地板检测就会停止工作。
标签: ios swift google-maps core-location indoor-positioning-system