我正在使用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)
}
一旦我加载谷歌地图,我就开始从CLLocation获得地板为零。并开始执行以下代码行。
floorLabel.text = "No floor detected"
有谁知道它出了什么问题?
由于文档,您应该首先打开Indoor Maps
:
mapView.isIndoorEnabled = true
文件还说:
平面图可在特定位置使用。如果要在应用程序中突出显示的建筑物没有楼层平面图数据,则可以:1(直接将楼层平面图添加到Google地图。这将使您的计划可供 Google 地图的所有用户使用。 2( 将平面图显示为地面叠加。这将仅允许应用程序的用户查看您的平面图。
还要考虑
默认情况下,地图上不显示任何位置数据。您可以通过在GMSMapView上设置myLocationEnabled来启用蓝色的"我的位置"点和指南针方向
。
mapView.isMyLocationEnabled = true
更多细节。