当我想查询当前用户地址附近的所有用户地址时,为什么会出现此错误:
我的代码:
openMapPage()
{
// GETTING THE CURRENT USER ADDRESS FOR LATITUDE AND LONGTITUDE
var uid = firebase.auth().currentUser.uid;
var ref = firebase.database().ref("request/" + uid);
ref.once("value").then((snapshot) => { // <------ Here!
var a = snapshot.exists(); // true
var c = snapshot.hasChild("reqdetails"); // true
var d = snapshot.child('reqdetails').exists();
var requestsKey = snapshot.key;
var requestsValue = snapshot.val();
ref.once('value', (request) => {
var currentUserAddress = request.val().regdetails.address;
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': currentUserAddress}, (results, status) => {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
this.latlng = new google.maps.LatLng(latitude, longitude);
//console.log("HAHAH current user");
//var meterLimit = this.latlng;
//var userAddress = new LatLng(currentUserAddress);
//console.log("SURESH IS COOL");
}
});
});
//END OF CURRENT USER
});
// GETTING THE ALL USER ADDRESS FOR LATITUDE AND LONGTITUDE
var ref1 = firebase.database().ref("request");
ref1.once("value").then((snapshot1) => { // <------ Here!
var a = snapshot1.exists(); // true
var c = snapshot1.hasChild("reqdetails"); // true
var d = snapshot1.child('reqdetails').exists();
var requestsKey = snapshot1.key;
var requestsValue = snapshot1.val();
snapshot1.forEach((childSnapshot) => { // <------ And here!
var requestKey = childSnapshot.key;
var requestValue = childSnapshot.val();
var reqdetails = requestValue.reqdetails;
var AllUserAddress = requestValue.regdetails.address;
var geocoder1 = new google.maps.Geocoder();
geocoder1.geocode( { 'address': AllUserAddress}, (results, status) => {
var limit = 10;
if (status == google.maps.GeocoderStatus.OK) {
var latitude1 = results[0].geometry.location.lat();
var longitude1 = results[0].geometry.location.lng();
this.latlng1 = new google.maps.LatLng(latitude1, longitude1);
//var userAddress = new LatLng(currentUserAddress);
//console.log(latlng1);
var dist: number = parseInt((google.maps.geometry.spherical.computeDistanceBetween(this.latlng,this.latlng1) / 1000).toFixed(2));
if(dist < limit)
{
console.log(dist);
console.log(AllUserAddress);
this.getRequest = this.angFire.list('request', {
query: {
orderByChild: AllUserAddress,
startAt: 'regdetails'
}
})
}
}
});
});
});
}
正如您在代码的这一部分中所看到的那样,我想查询当前用户地址附近的所有用户:但这不允许我这样做。
this.getRequest = this.angFire.list('request', {
query: {
orderByChild: AllUserAddress,
startAt: 'regdetails'
}
})
我得到的错误:
答案 0 :(得分:2)
使用startAt
时,必须使用键和值传入一个对象作为第二个参数。例如。 startAt: { value: 'some-value', key: 'some-key' }.
的Src:https://github.com/angular/angularfire2/blob/master/docs/4-querying-lists.md