Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何使用Swift查询Firebase中最近的用户?_Ios_Swift_Firebase_Firebase Realtime Database_Cllocationdistance - Fatal编程技术网

Ios 如何使用Swift查询Firebase中最近的用户?

Ios 如何使用Swift查询Firebase中最近的用户?,ios,swift,firebase,firebase-realtime-database,cllocationdistance,Ios,Swift,Firebase,Firebase Realtime Database,Cllocationdistance,我想找到离我位置最近的用户。firebase数据库中的My节点(例如最长5km),如下图所示 + users + user_id0 - latitude: _ - longitude: _ 有没有办法在这个半径范围内找到准确的用户。否则,我应该使用CLLocation distance方法检查每个用户离我最近的位置。我强烈建议使用类似的方法 要设置它,您的数据结构将稍有改变。您仍然可以在用户上存储lat/lng,但您还将创建一个名为users\u locations 您的u

我想找到离我位置最近的用户。firebase数据库中的My节点(例如最长5km),如下图所示

+ users
  + user_id0
    - latitude: _
    - longitude: _

有没有办法在这个半径范围内找到准确的用户。否则,我应该使用
CLLocation distance
方法检查每个用户离我最近的位置。

我强烈建议使用类似的方法

要设置它,您的数据结构将稍有改变。您仍然可以在用户上存储lat/lng,但您还将创建一个名为
users\u locations

您的
users\u locations
表将通过Geofire填充,看起来像这样

users_locations
  user_id0:
    g: 5pf666y
    l:
      0: 40.00000
      1: -74.00000
通常,这是在Geofire中存储位置的方式,但您可以将其设置为在创建/更新用户对象时保存位置

let geofireRef = FIRDatabase.database().reference().child("users_locations")
let geoFire = GeoFire(firebaseRef: geofireRef)
geoFire.setLocation(CLLocation(latitude: lat, longitude: lng), forKey: "user_id0")
users\u locations
中保存位置后,可以使用
GFQuery
查询特定范围内的所有用户

let center = CLLocation(latitude: yourLat, longitude: yourLong)
var circleQuery = geoFire.queryAtLocation(center, withRadius: 5)

var queryHandle = circleQuery.observeEventType(.KeyEntered, withBlock: { (key: String!, location: CLLocation!) in
   println("Key '\(key)' entered the search area and is at location '\(location)'")
})

我强烈推荐使用类似的东西

要设置它,您的数据结构将稍有改变。您仍然可以在用户上存储lat/lng,但您还将创建一个名为
users\u locations

您的
users\u locations
表将通过Geofire填充,看起来像这样

users_locations
  user_id0:
    g: 5pf666y
    l:
      0: 40.00000
      1: -74.00000
通常,这是在Geofire中存储位置的方式,但您可以将其设置为在创建/更新用户对象时保存位置

let geofireRef = FIRDatabase.database().reference().child("users_locations")
let geoFire = GeoFire(firebaseRef: geofireRef)
geoFire.setLocation(CLLocation(latitude: lat, longitude: lng), forKey: "user_id0")
users\u locations
中保存位置后,可以使用
GFQuery
查询特定范围内的所有用户

let center = CLLocation(latitude: yourLat, longitude: yourLong)
var circleQuery = geoFire.queryAtLocation(center, withRadius: 5)

var queryHandle = circleQuery.observeEventType(.KeyEntered, withBlock: { (key: String!, location: CLLocation!) in
   println("Key '\(key)' entered the search area and is at location '\(location)'")
})

如果您不想使用Geofire,另一个选项是查询任意方向(纬度/经度)5km范围内的所有用户,这将为您提供比5km半径范围内更多的用户。然后,与较小的用户子集进行CLLocation距离比较。最终,您将不得不为未进行切割的用户(即,在纬度和经度上相距5公里的拐角处的用户)进行di,但您一定要让直接相距5公里的用户直接N/S或e/W。如果您不想使用Geofire,另一个选项是查询任何方向相距5公里的所有用户(纬度/经度),这将为您提供比5km半径范围内更多的用户。然后,使用较小的用户子集,进行CLLocation距离比较。您将不得不为未进行切割的用户(即位于角落的用户,纬度和经度距离为5km)进行di,但您肯定会直接从南北或东西方向找到5公里以外的用户。
pod'GeoFire',“~>1.1”
我收到了这些错误:
Firebase
所需的
Podfile
-
Firebase(=3.11.0)
所需的
Podfile.lock
-
Firebase(~>2.1)
所需的
我该怎么办?你必须用桥头手动拖入,请参见
pod'GeoFire','~>1.1'
我收到了这些错误:
Firebase
需要由
Podfile
-
Firebase(=3.11.0)
需要由
Podfile.lock
-
Firebase(~>2.1)
需要由
GeoFire.1.0)
我该怎么办?您必须使用桥头手动拖动,请参见