gpt4 book ai didi

swift - 如何将 Geofire 与 Swift 结合使用来存储来自一个模拟器的位置,然后在另一个模拟器中显示该位置。

转载 作者:行者123 更新时间:2023-11-28 12:14:46 25 4
gpt4 key购买 nike

我正在使用 Swift 构建一个 iOS 来共享位置。有谁知道如何使用 Geofire 和 Swift 从一个模拟器存储位置,然后在另一个模拟器中显示存储的位置?

非常感谢。

最佳答案

首先尝试如下使用 cocopods,

pod 'Firebase', '~>4.0'
pod 'Firebase/Auth'
pod 'Firebase/Database'
pod 'Firebase/Storage'
pod 'GeoFire', :git => 'https://github.com/firebase/geofire-objc.git'

使用以下代码从 Geofire 设置和获取位置。

struct FndDatabase {
static let LOCATION = Database.database().reference().child("userlocation")
static let GEO_REF = GeoFire(firebaseRef: LOCATION)
}


func setUserLocation(location: CLLocation) {
let user = Auth.auth().currentUser?.uid //userid for the logged in user
if let uid = user {
FndDatabase.GEO_REF?.setLocation(location, forKey: uid)
}
}

func getLocation() -> CLLocation? {
var loc: CLLocation?
if let uid = Auth.auth().currentUser?.uid {
FndDatabase.GEO_REF?.getLocationForKey(uid, withCallback: { (location, err) in
if err != nil {
print( "Error getting Userlocation from Geofire \(err.debugDescription)")
} else {
print( "UserLocation is available \(location.debugDescription)")
loc = location
}
})

}
return loc
}

如果您看到此错误 'FirebaseDatabase/FirebaseDatabase.h' file not found。

然后执行此操作,从 pod 中选择 FirebaseDatabase.framework 并将其链接到 Geofire,如图所示

image gefire with firebase

示例代码已上传至:https://github.com/ledwinson/firebasegeo

A sample in firebase after storing location is shown below.

关于swift - 如何将 Geofire 与 Swift 结合使用来存储来自一个模拟器的位置,然后在另一个模拟器中显示该位置。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47129318/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com