0

I have a problem with global variables in javascript. Why latitude and longitude don't change?

var latitude;
var longitude;
  function initMap() {
    var reportDb = firebase.database().ref("Report");
    reportDb.once("value").then(function(snapshot) {
      snapshot.forEach(function(childSnapshot) {
        longitude = childSnapshot.child("longitudine").val();
        latitude = childSnapshot.child("latitudine").val();
      });
    })window.alert(longitude);}

same problem with latitude

  • 1
    They do change. You are alerting them **before** they change. – Quentin Jun 05 '18 at 16:10
  • You also have the problems that you missed out a `;` and **never call** `initMap`. – Quentin Jun 05 '18 at 16:11
  • How I can use a changed values? I've used alert for test – Capitan Jun 05 '18 at 16:13
  • There's a big yellow box at the top of the page with a link in it. Follow the link. Read the answers there. – Quentin Jun 05 '18 at 16:14
  • why the frist work and second no? – Capitan Jun 05 '18 at 16:39

0 Answers0