【问题标题】:My location is not displayed on the map in MapKit我的位置没有显示在 MapKit 的地图上
【发布时间】:2019-02-10 14:50:00
【问题描述】:

当我使用 let viewRegion = MKCoordinateRegionMakeWithDistance((userLocation?.coordinate)!, 600, 600) 时它很好,但是显然 Swift 现在已经用

让 viewRegion = MKCoordinateRegion(center: (userLocation?.coordinate)!, latitudinalMeters: 600, verticalMeters: 600)

我的位置不再出现在地图上,地图显示正确的区域。这是我的代码。

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    let locValue:CLLocationCoordinate2D = manager.location!.coordinate
    print("locations = \(locValue.latitude) \(locValue.longitude)")
    let userLocation = locations.last
    let viewRegion = MKCoordinateRegion(center: (userLocation?.coordinate)!, latitudinalMeters: 600, longitudinalMeters: 600)

    self.map.setRegion(viewRegion, animated: true)


}

【问题讨论】:

    标签: ios swift location mapkit


    【解决方案1】:

    首先希望您没有忘记从CLLocationManagerDelegateMKMapViewDelegate 扩展您的视图控制器。
    您可以通过调用
    userLocation = self.locationManager.location

    从班级中的任何位置直接从 locationManager 变量 private let locationManager: CLLocationManager = CLLocationManager() 访问用户位置

    也不要忘记将您的视图控制器委托给位置管理器和地图视图:

    locationManager.delegate = self
            mapView.delegate = self
    

    【讨论】:

      猜你喜欢
      • 2019-12-24
      • 2019-02-03
      • 2023-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多