Javascript 如何在基于Firebase的react本机应用程序中获取附近用户的列表?
我正在开发一个基于地图的应用程序,react native和Firebase作为后端,我一直使用附近的用户功能, 我使用react-native地图进行地理定位,react-native firebase 现在,在我的应用程序中,我有两种类型的用户(最终用户、提供商),注册后,我保存了关于他们的数据,其中包含他们的位置(Lat、Long), 目前我正在使用终端用户应用程序,我保存了一些关于提供商(位置)的伪造数据,我不知道如何让所有提供商靠近我的位置 这是我的数据库[提供者] 这是我向用户获取当前位置的代码,我尝试了一些查询来获取附近的提供商,但现在失败了:(,我可以很容易地获取所有提供商,但不包括附近的bot 所以Javascript 如何在基于Firebase的react本机应用程序中获取附近用户的列表?,javascript,reactjs,firebase,react-native,firebase-realtime-database,Javascript,Reactjs,Firebase,React Native,Firebase Realtime Database,我正在开发一个基于地图的应用程序,react native和Firebase作为后端,我一直使用附近的用户功能, 我使用react-native地图进行地理定位,react-native firebase 现在,在我的应用程序中,我有两种类型的用户(最终用户、提供商),注册后,我保存了关于他们的数据,其中包含他们的位置(Lat、Long), 目前我正在使用终端用户应用程序,我保存了一些关于提供商(位置)的伪造数据,我不知道如何让所有提供商靠近我的位置 这是我的数据库[提供者] 这是我向用户获取
import React,{Component}来自'React';
从“react native maps”导入MapView,{Marker};
从“react native”导入{View,Text,StyleSheet,Dimensions,PermissionsAndroid};
设{width,height}=Dimensions.get('window');
常数纬度=50.78825;
常数经度=51.4324;
常数纬度δ=0.0922;
常数经度_δ=0.0421;
类映射扩展组件{
建造师(道具){
超级(道具);
此.state={
错误:null,
宽度:宽度,
marginBottom:1,
地区:{
纬度:纬度,
经度:经度,
纬度三角洲:纬度三角洲,
经度三角洲:经度三角洲,
}
};
}
requestLocationPermission=async()=>{
const LocationPermission=wait permissions和roid.request(
PermissionsAndroid.PERMISSIONS.ACCESS\u FINE\u位置
// , {
//“消息”:“此应用程序需要访问您的位置,好吗?”
// }
)
if(LocationPermission==PermissionsAndroid.RESULTS.grated){
navigator.geolocation.getCurrentPosition(
//将为您提供当前位置
位置=>{
常量经度=position.coords.longitude;
常数纬度=位置坐标纬度;
这是我的国家({
地区:{
纬度,
经度,
纬度三角洲:纬度三角洲,
经度三角洲:经度三角洲,
}
})
},
error=>警报(error.message),
{enableHighAccurance:true,超时:20000,最大值:1000}
);
this.watchID=navigator.geolocation.watchPosition(位置=>{
控制台日志(位置);
常量经度=position.coords.longitude;
常数纬度=位置坐标纬度;
这是我的国家({
地区:{
纬度,
经度,
纬度三角洲:纬度三角洲,
经度三角洲:经度三角洲,
}
});
});
}
}
异步组件didmount(){
等待此消息。requestLocationPermission()
};
render(){
const{region}=this.state;
返回(
console.log(this.state.region)}
显示支持位置
区域={region}
loadingEnabled={true}
//style={StyleSheet.absoluteFill}
textStyle={{color:'#bc8b00'}}
containerStyle={{backgroundColor:'white',borderColor:'#BC8B00'}}
>
{/*{this.state.region.latitude}*/}
);
}
}
const styles=StyleSheet.create({
容器:{
弹性:1,
为内容辩护:“中心”,
对齐项目:“居中”,
flexDirection:'行',
justifyContent:'之间的空间',
填充:30,
弹性:1,
对齐项目:“中心”
},
地图:{
位置:'绝对',
zIndex:-1,
排名:0,
左:0,,
右:0,,
底部:0,
},
});
导出默认地图;
如果有人有兴趣帮助我,这是我的
你找到解决方案了吗?我正在尝试创建firebase函数来处理它,但迄今为止没有成功…Hello@David,我通过在前端使用而不是在firebase云函数来立即解决它。你能分享一些代码吗?这样我就可以理解我该如何处理它了?谢谢你获取所有用户,然后应用过滤?我想要只获取靠近我的用户…是的,主要思想是获取所有用户,然后根据我的位置和离我有多远进行过滤以获取所有用户“我从手机发送了此评论,我稍后将添加代码”
import React, { Component } from 'react';
import MapView, { Marker } from 'react-native-maps';
import { View, Text, StyleSheet, Dimensions, PermissionsAndroid } from 'react-native';
let { width, height } = Dimensions.get('window');
const LATITUDE = 50.78825;
const LONGITUDE = 51.4324;
const LATITUDE_DELTA = 0.0922;
const LONGITUDE_DELTA = 0.0421;
class Map extends Component {
constructor(props) {
super(props);
this.state = {
error: null,
width: width,
marginBottom: 1,
region: {
latitude: LATITUDE,
longitude: LONGITUDE,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA,
}
};
}
requestLocationPermission = async () => {
const LocationPermission = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
// , {
// 'message': 'This App needs to Access your location, OK?'
// }
)
if (LocationPermission === PermissionsAndroid.RESULTS.GRANTED) {
navigator.geolocation.getCurrentPosition(
//Will give you the current location
position => {
const longitude = position.coords.longitude;
const latitude = position.coords.latitude;
this.setState({
region: {
latitude,
longitude,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA,
}
})
},
error => alert(error.message),
{ enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 }
);
this.watchID = navigator.geolocation.watchPosition(position => {
console.log(position);
const longitude = position.coords.longitude;
const latitude = position.coords.latitude;
this.setState({
region: {
latitude,
longitude,
latitudeDelta: LATITUDE_DELTA,
longitudeDelta: LONGITUDE_DELTA,
}
});
});
}
}
async componentDidMount() {
await this.requestLocationPermission()
};
render() {
const { region } = this.state;
return (
<View style={styles.container}>
<MapView
style={[styles.map, { width: this.state.width }]}
style={StyleSheet.absoluteFill}
onMapReady={() => console.log(this.state.region)}
showsUserLocation
region={region}
loadingEnabled={true}
// style={StyleSheet.absoluteFill}
textStyle={{ color: '#bc8b00' }}
containerStyle={{ backgroundColor: 'white', borderColor: '#BC8B00' }}
>
<Marker
coordinate={this.state.region}
title="Hello Title"
description="description..."
/>
</MapView>
{/* <Text>{this.state.region.latitude}</Text> */}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
flexDirection: 'row',
justifyContent: 'space-between',
padding: 30,
flex: 1,
alignItems: 'center'
},
map: {
position: 'absolute',
zIndex: -1,
top: 0,
left: 0,
right: 0,
bottom: 0,
},
});
export default Map;