我正在使用GeoFirestore对我的Firebase Firestore运行地理查询。它似乎通常可以正常工作,但是返回的结果比半径大于25英里的测试所返回的结果要多。我的Firestore中最近的位置距离我要测试的位置103英里。我已经以25英里的增量进行了测试。 25英里不返回任何位置,50英里返回最接近的位置,75英里返回最接近的位置,100英里返回我所有的测试位置。知道我在做什么错吗?
func getFacilites() {
self.facilities = [[String: Any]]()
let currentLatitude = self.currentLocation.coordinate.latitude
let currentLongitude = self.currentLocation.coordinate.longitude
let geoFireStore = Constants.geoFirestore
let circleQuery = geoFireStore.query(withCenter: GeoPoint(latitude: currentLatitude, longitude: currentLongitude), radius: milesToKilometers())
let _ = circleQuery.observeReady {
print("All initial data has been loaded and events have been fired!")
}
let _ = circleQuery.observe(.documentEntered, with: { (key, location) in
Constants.firestore.collection("facilities").document(key!).getDocument { (document, error) in
if let document = document, document.exists {
self.facilities?.append(document.data()!)
self.addFaciltiesToMap()
} else {
print("Document does not exist.")
}
}
})
}
func milesToKilometers() -> Double {
// self.searchDistance is a Double value
return self.searchDistance * 1.60934
}