简体   繁体   中英

Retriving data from firebase web

I am trying to fetch the data for website using java script. Problem I am getting is that I am unable to get the key of Users-->history-->location-->from-->(lat,lng). I am unable to find a syntax of it.

数据库图片

Code I am trying is

   var ref = firebase.database().ref("history/" + keys  +"/location/from");

ref.on('value',gotDataa,errDataa);

function gotDataa(data){
    //console.log(data.val());
    var from = data.val();
    var keys=Object.keys(from);
    console.log(keys);
    for(var i=0 ; i<keys.length;i++)
    {
        var k=keys[i];
        var name = from[k].customer;
        var phone = from[k].driver;

        //console.log(name,phone,imag);
        $('ul').append( '<li>' + name +" : " + phone+ '</li>' );
    }
}

代码错误

This should print the lat and lng of each item in the history:

var ref = firebase.database().ref("history/");

ref.on('value',gotDataa,errDataa);

function gotDataa(data){
  data.forEach(function(child) {
    var from = data.val().location.from;
    console.log(from.lat+","+from.lng);
  });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM