我有一个商店列表如下:
"store" : {
"2" : {
"address" : "amman",
"ctime" : "17:05:00",
"g" : "9q8yyxfgs8",
"id" : "11",
"l" : [ 31.9453666, 35.9283716 ],
"name" : "Kaluti",
"otime" : "00:00:00",
"phone" : "0795080034",
"userId" : "4"
},
"7" : {
"address" : "amman",
"ctime" : "01:00:00",
"g" : "9q8yyxfgs8",
"id" : "7",
"l" : [ 31.9453666, 35.9283716 ],
"name" : "Zalloum33",
"otime" : "05:00:00",
"phone" : "0795080034",
"userId" : "2"
},
"11" : {
"address" : "amman",
"ctime" : "17:05:00",
"g" : "9q8yyxfgs8",
"id" : "11",
"l" : [ 31.9453666, 35.9283716 ],
"name" : "Kaluti",
"otime" : "00:00:00",
"phone" : "0795080034",
"userId" : "4"
},
"12" : {
"address" : "asd",
"ctime" : "22:00:00",
"g" : "9q8yyxfgs8",
"id" : "12",
"l" : [ 37.7922, -122.4056973 ],
"name" : "Amam",
"otime" : "10:00:00",
"phone" : "0795126776",
"userId" : "4"
},
"19" : {
".priority" : "9q8yyxfgs8",
"g" : "9q8yyxfgs8",
"id" : "10",
"l" : [ 37.7922, -122.4056973 ],
"name" : "ahmad"
}
}
当我尝试使用此代码获取此位置时,查询未返回任何值
let center = CLLocation(latitude: 31.97375, longitude: 35.872316)
if let circleQuery = geoFire?.query(at: center, withRadius: 1.0) {
_ = circleQuery.observe(.keyEntered) { (key, location) in
print("Key '\(key)' entered the search area and is at location '\(location)'")
}
circleQuery.observeReady{
print("All initial data has been loaded and events have been fired for circle query!")
}
}
但如果我尝试使用相同的代码,只需用
更改CLLocationlet center = CLLocation(latitude: 37.7832889, longitude: -122.4056973)
它的返回数据。
请告诉我问题在哪里?
答案 0 :(得分:0)
您需要根据需要调整半径。在您的示例中,半径为1.0米,仅返回距离中心位置1米范围内的物体。尝试将其增加到500.0米,就像我在下面的示例中所做的那样:
let center = CLLocation(latitude: 31.97375, longitude: 35.872316)
if let circleQuery = geoFire?.query(at: center, withRadius: 500.0) {
_ = circleQuery.observe(.keyEntered) { (key, location) in
print("Key '\(key)' entered the search area and is at location '\(location)'")
}
circleQuery.observeReady{
print("All initial data has been loaded and events have been fired for circle query!")
}
}