首页 > 解决方案 > 如何修复函数“didUpdateLocations”上的更新用户位置?

问题描述

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

这是用于应用程序上的谷歌地图 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)
    }

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

标签: iosswift

解决方案


请实施开始更新用户位置。让我知道它是否仍然无法正常工作

locationManager.delegate = self
locationManager.startUpdatingLocation()

推荐阅读