Need Help to Debug my Code. My problem is that my latitude and longitude is read as undefined in my position function.

Joined
Oct 26, 2022
Messages
1
Reaction score
0
JavaScript:
  var ref = firebase.database().ref('Location/Lat');
  var latitude;
  var longitude;
    ref.on("value", function(snapshot) {
    console.log(snapshot.val());
    latitude = snapshot.val().Latitude;
    longitude = snapshot.val().Longitude;
    console.log(latitude, longitude);
    userLocation(latitude, longitude);
    }, function (error) {
   console.log("Error: " + error.code);
    });

// Find user location
function userLocation (latitude, longitude){
    console.log(latitude, longitude)
    try{
    // Get position fn
    function position (c, lt, lg){
        console.log(c.coords);
        let lat = lt.latitude;
        let lng = lg.longitude;
        let coords = [lng, lat];
        // Show map location
        mapBoxFn(coords);
    };
    // Error fn
    function error (err){
        alert(`ERROR(${err.code}): ${err.message}`);
    };
 
Joined
Nov 13, 2020
Messages
302
Reaction score
38
This might go unanswered because lots of things are missing and it looks like you're not using pure JS.
Finally where and what is c, It, lg and how did you get them in the function?
 
Joined
Mar 11, 2022
Messages
227
Reaction score
32
This might go unanswered because lots of things are missing and it looks like you're not using pure JS.
Finally where and what is c, It, lg and how did you get them in the function?
Looks like firebase crab.

To the thread starter @RedWinter
There is no REACT, JQUERY or other Open Source sections in this forums yet. So please use pure JS please.
That's no patronizing. But Open Source can and will be used in a millions of ways. So your chance to get help is 1:1000000 because at least one of "yet only a few" JS Users in here should have experiences with exactly your issue. It's not even helping if you show more code. Because it is not pure JS.

Maybe we can help you with pure JS.

What is your goal? Getting latitude and longitude from USERS? Getting it constantly? That's easy. So just tell us.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,818
Messages
2,569,727
Members
45,676
Latest member
ManuelaHol

Latest Threads

Top