2017-08-08 96 views
3

當我想查詢所有在附近的當前用戶地址的用戶地址爲什麼會出現這樣的錯誤:Query.orderByChild失敗:第一個參數是一個無效的路徑

我的代碼:

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' 
     } 
    }) 

我得到的錯誤:

enter image description here

回答

相關問題