谷歌地图更新位置 - 斯威夫特



我正在使用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)")
}

do

locationManager.stopUpdatingLocation()

您也可以添加一次bool变量

最新更新