无法在Firebase云中正确返回javafire中的geofire数据

时间:2018-08-17 12:54:07

标签: javascript firebase google-cloud-functions geofire

let geolocationRef = db.ref("geolocations/");

var lat = data.lat;
var lon = data.lon;
var area = data.area;
var reqFacilities = data.facilities || [];
var geoFire = new GeoFire(geolocationRef);
var geoQuery = geoFire.query({
    center: [parseFloat(lat), parseFloat(lon)],
    radius: parseFloat(area) // the minimum radius that will return
});

var hotelDataArray = [];
geoQuery.on("key_entered", function(key, location, distance) {
  let adsRef = db.ref("ads/" + key);
    adsRef.on("value", (snapshot) => {
        if (snapshot.val().facilities !== undefined) {
            let facilityArray = Object.keys(snapshot.val().facilities);
            if (reqFacilities.every(val => facilityArray.includes(val))) {
      console.log("Pushed") 
                 hotelDataArray.push({key: key, distance: distance.toFixed(2), data :snapshot.val()});
            }
        }
    })

});
console.log(hotelDataArray,"last")  

返回{hotelDataArray};

});

这是我的地火代码,可让您使用指定设施获得最近的酒店 但它不能正确返回数据 控制台打印如

  • []最后

  • 按下

返回零值

我需要对配备设施的酒店进行分类,如何正确对其进行分类 请帮助我

0 个答案:

没有答案