Ultimately I'm attempting to get the user's location with geolocation and then feed that location into a Google Map so that the map displays the approximate current location. My javascript seems to return latitude and longitude of the current location but I'm having trouble referencing these variables outside the scope of my javascript function. Probably a rookie mistake, but been pounding my head against the wall for some time here.

// Check to see if this browser supports geolocation.
if (navigator.geolocation) {

    // This is the location marker that we will be using on the map. Let's store a reference to it here so that it can be updated in several places.
    var locationMarker = null;
    var myLat = null;
    var myLng = null;
    var myLocation = null;

    // Get the location of the user's browser using the native geolocation service.
        function (position) {

            // Check to see if there is already a location. There is a bug in FireFox where this gets invoked more than once with a cached result.
            if (locationMarker){

            // Log that this is the initial position.
            console.log( "Initial Position Found" );
            // Assign coordinates to global variables
            myLat = position.coords.latitude;
            myLng = position.coords.longitude;
            myLocation = myLat + ", " + myLng;
            // If I alert myLocation here, the coordinates are there.



// If I alert myLocation here, the value is null
Notice my two comments in the code. I'm attempting to alert the myLocation variable for testing. In one area, I can successfully alert the value but when I attempt to alert it in the last line of my code, the value is null. I thought that by declaring the variable outside the scope of the function would make it a global variable and usable anywhere within the window object, but clearly I'm mistaken. Any idea how I can use the value of myLocation in another function for Google Maps?