Error: Invalid location: latitude must exist on GeoPoint

Error: Invalid location: latitude must exist on GeoPoint

在云函数中访问 firestore 文档时出现以下错误

"Error: Invalid location: latitude must exist on GeoPoint"

我在 firebase 日志中看到以下错误

Error: Invalid location: latitude must exist on GeoPoint at validateLocation (/srv/node_modules/geofirestore/dist/index.cjs.js:567:15) at calculateDistance (/srv/node_modules/geofirestore/dist/index.cjs.js:120:5) at /srv/node_modules/geofirestore/dist/index.cjs.js:1148:32 at Array.forEach () at /srv/node_modules/geofirestore/dist/index.cjs.js:1147:27 at Array.forEach () at new GeoJoinerGet (/srv/node_modules/geofirestore/dist/index.cjs.js:1146:19) at /srv/node_modules/geofirestore/dist/index.cjs.js:1432:72 at at process._tickDomainCallback (internal/process/next_tick.js:229:7)

我的index.ts文件

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';import * as geofire from 'geofirestore';

admin.initializeApp();

const db = admin.firestore();

const geofirestore = new geofire.GeoFirestore(db);
const geocollection = geofirestore.collection('posts');

export const sendPostToDevice = functions.firestore
.document('posts/{postId}')
.onCreate((snapshot, context) => {
const post = snapshot.get('content');

    const l = snapshot.get('l');

    const GeoPoint = admin.firestore.GeoPoint;

    const gp = new GeoPoint(37.4219983, -122.084);
    const query = geocollection.near({
        center: gp,
        radius: 1000
    });
    query.get().then((value) => {
        console.log(value);
    }).catch((err) => console.log(err));
    return null;
})

附加信息:我在我的 flutter 应用程序中使用 GeoFlutterFire 并在创建 GeoFirestore 所需的 Post 文档时存储附加字段(g:geohash 和 l:location 存储为地理点)。我怀疑错误是因为我如何存储字段 'g' 和 'l'.

我在 Cloud Functions 中使用 GeoFirestore 来查询附近的用户,检索他们的 FCM 令牌并将它们提供给 Firebase Messaging 以发送通知。

我需要以某种方式存储字段 g 和 l 吗?我们可以只使用 GeoFlutterFire 吗?

感谢您的帮助!

new GeoPoint(37.4219983, -122.084) 看起来不错,所以我怀疑它一定是您的 geocollection 对象的地理位置之一导致了问题。