如何在func“ didUpdateLocations”上修复更新用户位置?

时间:2019-08-02 02:48:23

标签: ios swift

我想在用户访问我的应用程序上的地图时更新位置。我使用func didUpdateLocations来获取用户位置,但是位置没有更新,当我在真实设备上运行时,某些单位仍然可用。请帮助我,谢谢。

这是针对应用程序上的google map sdk设计地图。

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    guard let currentLocation = locations.last else {
        return
    }

    //Update Camera
    let camera = GMSCameraPosition.camera(withLatitude: currentLocation.coordinate.latitude, longitude: currentLocation.coordinate.longitude, zoom: 18.0)
    mapView.animate(to: camera)

    if mapView.isHidden {
        mapView.isHidden = false
        mapView.camera = camera
    } else {
        mapView.animate(to: camera)
    }

运行项目时,帮助我获取确切的用户位置。谢谢。

1 个答案:

答案 0 :(得分:0)

请实施开始更新用户位置。让我知道它是否仍然无法运行

locationManager.delegate = self
locationManager.startUpdatingLocation()