我正在使用GeoFire来获取附近的位置,然后使用键来获取数据库引用,然后尝试将该数据推入数组,但无法使其正常工作。任何帮助都会很甜:)
let myArray = []
var database = firebase.database(); // Ref to Firebase Database
var geoFire = new GeoFire(database.ref('items_locations'));
const lat = location.coords.latitude;
const long = location.coords.longitude;
let radius = 5
let center = [lat, long];
let geoQuery = geoFire.query({
center: center,
radius: radius
});
geoQuery.on("key_entered", (key, location, distance) => {
let markers = firebase.database().ref(`items/${key}`).orderByKey();
markers.on('value', (snapshot) =>{
let name = snapshot.child("name").val()
myArray.push(name`enter code here`)
})
})
获取一个空数组