#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    204
    Rep Power
    2

    Google maps Latlng Global variable


    Hi

    Does anybody know why this is undefined? It's a normal global variable, yet google maps doesn't allow it

  2. #2
  3. No Profile Picture
    Super Moderator
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,007
    Rep Power
    2791
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    101
    Rep Power
    27
    I might not have had enough coffee yet this morning. But you have two variable names there, mylocation and myLocation. You never define a value for myLocation.

    Comments on this post

    • Winters agrees : Well spotted.
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    204
    Rep Power
    2
    Originally Posted by mod_speling
    I might not have had enough coffee yet this morning. But you have two variable names there, mylocation and myLocation. You never define a value for myLocation.
    Hi! Yes you are awake but that's not the problem

    The problem is that both the geolocation function and the getJSON are async.. I'm still trying to learm how to get around this.o
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    101
    Rep Power
    27
    Your example doesn't have any call to $.getJSON in it?
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    204
    Rep Power
    2
    Originally Posted by mod_speling
    Your example doesn't have any call to $.getJSON in it?
    Sorry, it's there but you don't see it what i'm trying to say is that they're both async. So it's the same problem there as in this example..

    I'm looking for a workaround but for now it's
    impossible to fill an array with data received from an async call
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    101
    Rep Power
    27
    Sorry, you lost me.
    impossible to fill an array with data received from an async call
    This... isn't true? No, not true.
    Code:
    var ary = array();
    $.getJSON("foo.php", function(data) {
        if (data.stuff) for (var i in data.stuff) ary.push(data.stuff[i]);
    });
    The array will contain data as soon as the request to foo.php completes. Yes, asynchronously. Whatever your question is, you haven't fully explain it yet, I think. Your original post said "Why is this undefined?" I assumed you meant the value logged from console.log(), which was undefined because the variable name was misspelled.

IMN logo majestic logo threadwatch logo seochat tools logo