【问题标题】:GeoFireStore where QueryGeoFireStore where 查询
【发布时间】:2018-10-27 23:26:22
【问题描述】:

我有以下 Firestore 数据库。此 Firestore 中的数据已添加 通过 geofirestore 模块https://github.com/geofirestore/geofirestore-js#example-usage.

如何使用 geofire Queries 查询此 Firestore 以查找字段 name="Sex" 的位置

请搜索 React native 的解决方案,谢谢。

enter image description here

【问题讨论】:

    标签: reactjs firebase native geofirestore


    【解决方案1】:

    您可能想查看docs for future queries you may have。但是,对于您想要的查询,它应该相当简单......

    // Create query listener
    
    const geoQuery = geoFirestore.query({
      center: new firebase.firestore.GeoPoint(10.38, 2.41),
      radius: 10.5,
      query: (ref) => ref.where('d.details.name', '==', 'Sex')
    });
    
    // Then listen for results as they come in
    const onKeyEnteredRegistration = geoQuery.on('key_entered', (key, document, distance) => {
      console.log(key + ' entered query at ' + document.coordinates.latitude + ',' + document.coordinates.longitude + ' (' + distance + ' km from center)');
    });
    

    【讨论】:

    • 谢谢先生 :) 我能弄明白:)
    【解决方案2】:

    上面回答了@MichaelSolati 的查询,适用于旧版本的 GeoFireStore (2.x.x)。 以下是 Michael 对 3.x.x 版本的相同查询(取自 Github Issue)。

    const geocollection: GeoCollectionReference = geofirestore.collection('Users');
    const geoQuery = geocollection.near({
        center: new firebase.firestore.GeoPoint(50.9235691,10.7218614),
        radius: 10.5
        }).where('d.details.name', '==', 'Sex');
    

    【讨论】:

    • 它不适用于“大于”
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-17
    相关资源
    最近更新 更多