首页 > 解决方案 > 谷歌地图更新位置 - 迅速

问题描述

我正在使用 api 谷歌地图。当我单击按钮时,我调用方法 locationManager.startUpdatingLocation()。但是这种方法监控我的位置,我只需要获取一次数据(坐标)。在这种情况下我应该使用什么?

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        let userLocation :CLLocation = locations[0] as CLLocation

        print("user latitude = \(userLocation.coordinate.latitude)")
        print("user longitude = \(userLocation.coordinate.longitude)")
}

标签: swiftiphoneapigoogle-mapsmaps

解决方案


locationManager.stopUpdatingLocation()

你也可以添加一次bool变量


推荐阅读