【发布时间】:2020-05-27 17:15:07
【问题描述】:
我正在尝试接近半径为 25 公里的“在线”用户,我正在使用以下代码使用 geofirestore-js 插件 (https://github.com/MichaelSolati/geofirestore-js) 执行地理查询
const geofirestore = new GeoFirestore(Firebase.firestore());
const geocollection = geofirestore.collection('location');
const query = geocollection.near({ center: coordinates, radius: 25 }).where('status' , '==' , 'online');
query.onSnapshot(querysnapshot => {
let nearByContact = []
querysnapshot.docs.forEach((change) => {
if (change.id !== store.user.uid) {
nearByContact.push({
coordinate: {
latitude: change.data().coordinates._latitude,
longitude: change.data().coordinates._longitude,
},
title: change.data().name,
description: change.distance.toFixed(2) + " km away",
image: change.data().avatarUrl,
profileId: change.id
})
}
})
同时使用 'near' 和 'where' 方法时返回 null。但是该查询适用于像这样的单个方法。
const query = geocollection.near({ center: coordinates, radius: 25 })
query.onSnapshot(querysnapshot => {.....
我想通过这两种方法查询firestore db 你能帮我解决这个问题吗?
【问题讨论】:
标签: firebase react-native google-cloud-firestore react-native-android geofirestore