【发布时间】:2019-02-01 18:06:42
【问题描述】:
我正在与 SWIFT 上的CoreLocation 合作,我想创建一个地理区域,我可以在其中查看用户是否在正确的位置。用户位于此坐标的示例:Lat: 44.8856828 and Lon: -93.2131653。我想在他周围设置一个200 米的区域,以确保数据正确,并且用户可以使用200-meter 区域检查该地点的任何部分。这就是我在代码中必须要做的!
override func viewDidLoad() {
latLabel.text = latStore
lonLabel.text = lonStore
readData()
regionLocation()
}
//Accessing the are around the user
func regionLocation() {
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
}
func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {
print("You enter the place")
}
func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) {
print("Your exit the place")
}
func locationManager(_ manager: CLLocationManager, didStartMonitoringFor region: CLRegion) {
print("Start monitoring")
locationManager.requestAlwaysAuthorization()
let currentRegion = CLCircularRegion(center: (locationManager.location?.coordinate)!, radius: 200, identifier: "Place")
locationManager.startMonitoring(for: currentRegion)
}
【问题讨论】:
-
您的做法是正确的,您面临哪些问题?也请将您的代码发布为代码/文本而不是图像。
-
@lorenzoliveto 在我的代码中,当我更改位置时,控制台中没有显示用户已离开 200 周长
标签: ios swift core-location latitude-longitude