Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 使用Geofirestore查询云Firestore地理点时出错_Reactjs_Firebase_React Native_Google Cloud Firestore_Geofirestore - Fatal编程技术网

Reactjs 使用Geofirestore查询云Firestore地理点时出错

Reactjs 使用Geofirestore查询云Firestore地理点时出错,reactjs,firebase,react-native,google-cloud-firestore,geofirestore,Reactjs,Firebase,React Native,Google Cloud Firestore,Geofirestore,我有一个云Firestore集合位置,其中包含地理点字段,我希望根据当前用户的位置进行查询以查找附近的位置 云Firestore似乎还不能做到这一点,但geofirestore似乎是可行的选择。我试图查询坐标为34.0103118.4962的CloudFireStore收集位置。但是,我得到了以下错误: [2019-05-26T19:28:26.891Z]@firebase/firestore:,firestore 6.0.4:内部未处理错误:,配置网络监控 以下是我所看到的: 数据收集位置加载

我有一个云Firestore集合位置,其中包含地理点字段,我希望根据当前用户的位置进行查询以查找附近的位置

云Firestore似乎还不能做到这一点,但geofirestore似乎是可行的选择。我试图查询坐标为34.0103118.4962的CloudFireStore收集位置。但是,我得到了以下错误:

[2019-05-26T19:28:26.891Z]@firebase/firestore:,firestore 6.0.4:内部未处理错误:,配置网络监控

以下是我所看到的:

数据收集位置加载到Cloud Firestore是否正确 Cloud Firestore地质点语法正确,数据正确 地理查询不工作 云Firestore数据:

反应组件搜索:


正如@MichaelSolati所指出的,您的数据结构必须如下所示:

{
  city: "Santa Monica",
  g: [34.0103, 118.4962],
  l: "wwh32rqk3e",
  location_id: "LA_00012",
  location_name: "Santa Monica Pier",
  state: "CA",
  street: "200 Santa Monica Pier,
  zip_code: "90401",
}
您的地理点必须替换为g,并且必须添加名为l的geohash子项


我希望有帮助

geofirestore文档需要以某种方式进行结构化,我想说的是,检查一下=>
// Imports: Dependencies
import React, { Component } from 'react';
import { Button, SafeAreaView, StyleSheet, Text, View } from 'react-native';
import 'firebase/firestore';
import { GeoCollectionReference, GeoFirestore, GeoQuery, GeoQuerySnapshot } from 'geofirestore';

// Screen: Search
class Search extends Component {
  constructor (props) {
    super(props);

    this.state = {
      location: null,
      errorMessage: null,
    };
  }

  // Get Nearest Locations
  getNearestLocations = async () => {
    try {
    // Create Firestore Reference
    const collection = firebase.firestore().collection('locations');

    // Query Limit (10)
    const limitQuery = collection.limit(10);

    // Geo Query
    const query = new GeoQuery(limitQuery).near({
      center: new firebase.firestore.GeoPoint(34.0103, 118.4962),
      radius: 10,
    });

    query.get().then((value) => {
      value.docs.forEach(doc => {
        console.log(doc);
      });
    });

    }
    catch (error) {
      console.log(error);
    }
  }

  render() {
    return (
      <SafeAreaView style={styles.container}>
        <Text>Search</Text>

        <Button title="Search" onPress={this.getNearestLocations} />
      </SafeAreaView>
     );
    }
  }

  // Styles
  const styles = StyleSheet.create({
    container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

// Exports
export default Search
{
  city: "Santa Monica",
  g: [34.0103, 118.4962],
  l: "wwh32rqk3e",
  location_id: "LA_00012",
  location_name: "Santa Monica Pier",
  state: "CA",
  street: "200 Santa Monica Pier,
  zip_code: "90401",
}