-1

I am a newbie in firebase. In my web app I have stored a set or coordinates in firebase. The structure looks like this:

{
  "pointdata" : {
    "-L0eZoI7sULutu5nVOgw" : {
      "lat" : 42.76314586689492,
      "lng" : -91.966552734375
    },
    "-L0eZoozb2cf7mC3DUTy" : {
      "lat" : 41.72213058512578,
      "lng" : -90.604248046875
    },
    "-L0eZp084Cs54IJ5IBoA" : {
      "lat" : 41.41801503608025,
      "lng" : -89.351806640625
    },
    "-L0eZpBHcXve-jEy_TYk" : {
      "lat" : 41.94314874732696,
      "lng" : -88.0224609375
    },
    "-L0eZpaftCzzM4EmXz4D" : {
      "lat" : 42.72280375732727,
      "lng" : -88.231201171875
    }
  }
}

I need these coordinates to be retrieved and stored as an array or arraylist:

{ [lat1, lng1] [lat2,lng2] .... } 

Thanks in advance for any help

David Rogers
  • 2,601
  • 4
  • 39
  • 84
  • You've included a link to a picture of the JSON tree in your question. Please replace that with the actual JSON as text, which you can easily get by clicking the Export JSON link in [your Firebase Database console](https://console.firebase.google.com/project/_/database/data/). Having the JSON as text makes it searchable, allows us to easily use it to test with your actual data and use it in our answer and in general is just a Good Thing to do. – Frank van Puffelen Dec 17 '17 at 15:57
  • Did it, thanks for the tip. – Yiannis Gavalos Dec 18 '17 at 17:10

1 Answers1

2

Get the points from database then push an array in forEach loop :

var pointsArr = [];
firebase.database().ref('pointdata').once('value', snapshot => {
    snapshot.forEach(point=>{
       pointsArr.push([point.val().lat, point.val().lng]);
  })
   console.log(pointsArr); // shows your points in array
})
Cappittall
  • 3,300
  • 3
  • 15
  • 23
  • Thank you , and a followup question. I am trying to use the afformentioned pointsArr to create a polyline path (setcoords) and with that , a polyline. My app seems to get stuck in the following loop : for (int c = 0; c < pointsArr.length; c++){ var coords = new google.maps.LatLng(pointsArr[c][1], pointsArr[c][2]) setofcoords.push(coords); } – Yiannis Gavalos Dec 17 '17 at 11:00
  • I think `new google.maps.LatLng(pointsArr[c][1], pointsArr[c][2])` should be `new google.maps.LatLng(pointsArr[c][0], pointsArr[c][1])` – Cappittall Dec 17 '17 at 20:50