【发布时间】:2020-05-07 05:44:24
【问题描述】:
在我的 Firestore 数据库中,我有用户表,其中包含用户的详细信息及其 GeoPoint。
我想通过检查数据库中的用户是否在我的范围内来获取我在 GMSCoordinateBounds 中的位置附近的用户。
有关该问题的更多查询评论。
目前我正在做的是但没有得到正确的结果:-
let visibleRegionn = mapView.projection.visibleRegion()
let bounds = GMSCoordinateBounds(region: visibleRegionn)
// we've got what we want, but here are NE and SW points
let northEast = bounds.northEast
let southWest = bounds.southWest
let geopoint1 = GeoPoint(latitude: northEast.latitude, longitude: northEast.longitude)
let geopoint2 = GeoPoint(latitude: southWest.latitude, longitude: southWest.longitude)
let docRef = Firestore.firestore().collection("Users")
let query =
docRef
.whereField("locationGeopoint", isLessThanOrEqualTo: geopoint1)
.whereField("locationGeopoint", isLessThanOrEqualTo: geopoint2)
query.getDocuments { snapshot, error in
if let error = error {
print("Error getting documents: \(error)")
} else {
for document in snapshot!.documents {
self.arrListMapData.append(document.data() as NSDictionary)
}
}
}
【问题讨论】:
-
您能否分享一下用户地理位置数据在 Firebase 中的样子?
-
pasteboard.co/J7g4LKc.png @zenwraight 请检查这张图片
标签: ios swift iphone xcode google-cloud-firestore