作为上述新手,我正在努力使用存储在Firebase中的位置详细信息来显示Google地图中的所有用户坐标。目前,该应用程序显示用户,而没有其他人。
我看过这些问题:
How to query nearest users in Firebase with Swift?
GeoFire Swift 3 - Saving and Updating Coordinates
Firebase Retrieving Data in Swift
但与这些不同的是,我只记录实际位置(目前为止),并且对展示半径内的位置不感兴趣,而是对存储的所有位置感兴趣。
以下是主要部分:
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last
let lat = location?.coordinate.latitude
let long = location?.coordinate.longitude
let ref = Database.database().reference().child("user_locations")
let geoFire = GeoFire(firebaseRef: ref)
geoFire.setLocation(location!, forKey: deviceUID) //using device ID as yet to add users
let camera = GMSCameraPosition.camera(withLatitude: (lat)!, longitude:(long)!, zoom:14)
self.mapView.animate(to: camera)
}
这是我在locationManager
中考虑过的,但不知道如何申请,或者在没有半径的情况下使用:
let center = CLLocation(latitude: lat!, longitude: long!)
let circleQuery = geoFire.query(at: center, withRadius: 5)
_ = circleQuery.observe(.keyEntered, with: { (key: String!, location: CLLocation!) in
print("Key '\(key)' in area at location '\(location)'")
任何帮助都将不胜感激。