所以我需要将用户的位置坐标存储在数据库中。到目前为止,我已经创建了一个具有数据库的 viewcontroller.swift ,但我将 mapkit 附加到另一个 View Controller ,它在其中打印出坐标。我想知道如何获取这些坐标并将其存储在我的第一个 View Controller 中创建的数据库中。
打印坐标
func locationManager(_ manager: CLLocationManager, didUpdateLocations
locations: [CLLocation]) {
if let location = locations.first{
print(location.coordinate)
}
此处需要输入
let building = buildingField.text?.trimmingCharacters(in:
.whitespacesAndNewlines)
if(building?.isEmpty)!{
print("Building is Empty")
}
if sqlite3_bind_text(stmt, 5, building, -1, nil) != SQLITE_OK{
print("Error binding building")
}
最佳答案
您始终可以通过在当前 VC 中创建该类的实例来访问另一个 ViewController 的变量。在这种情况下,您可以创建一个 VC 实例,其中 SQLite DB 代码存在于 MapViewController 中,然后将坐标分配给第一个 VC 中的变量。如果您需要执行诸如通过传递坐标写入数据库之类的任务,那么您可以使用 NSNotificationCenter 类,它允许您在 View Controller 之间进行通信。下面的链接应该能让您更好地了解我在说什么。
引用:
关于swift - 需要快速检索用户坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50283265/