swift - 谷歌地图更新位置 - 迅速
问题描述
我正在使用 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)")
}
解决方案
做
locationManager.stopUpdatingLocation()
你也可以添加一次bool
变量
推荐阅读
- c++ - C ++如何在用户输入三个错误的猜测后停止我的代码
- snowflake-cloud-data-platform - Jitterbit Cloud Studio 雪花查询转换错误 - qName 和根名称 CASE SENSITIVITY
- rust - 为什么 entry 需要 key 的所有权?
- excel - .FIND 找不到日期
- python-3.x - 从 AppleScript 启动 Python 脚本会在读取一行时产生 EOFError
- mysql - 我如何进行 mysql 查询以在相同的结果中找到具有相同日期和 EstID 的 RandomID?
- javascript - 当 div 处于水平内容滚动视图中时,如何将类添加到正确的导航项?
- reactjs - How to check if a video source has audio in ReactJS?
- amazon-web-services - S3 对象的跨账户复制
- postgresql - 在 Postgres 13 中使用 anycompatible 伪类型的安全除法功能,明白了吗?