title: Geolocation data saved in a variable/localstorage
body: <p>i have a problem with the Geolocation API -.-'</p>
  
  <p>I'm using the FirefoxOS Boilerplate App (<a href="https://github.com/robnyman/Firefox-OS-Boilerplate-App" rel="nofollow">https://github.com/robnyman/Firefox-OS-Boilerplate-App</a>) for create a simple html5 app.</p>
  
  <p>The problem is simple: I would like the data (lat/lon) obtained from the API are returned by a function as an array.
  All the examples that i have found uses the data on the fly for show the maps or insert in a div (as also this boilerplate).</p>
  
  <pre><code>navigator.geolocation.getCurrentPosition(function (position) {
              geolocationDisplay.innerHTML = "&lt;strong&gt;Latitude:&lt;/strong&gt; " + position.coords.latitude + ", &lt;strong&gt;Longitude:&lt;/strong&gt; " + position.coords.longitude;
              geolocationDisplay.style.display = "block";
          },
          function (position) {
              geolocationDisplay.innerHTML = "Failed to get your current location";
              geolocationDisplay.style.display = "block";
          });
  </code></pre>
  
  <p>This is the code of the boilerplate for the Geolocation...</p>
  
  <p>I would want a function like get_location that return me the data, but after days of testing/google  search I gave up and I ask you who are more experienced with callback/scope in Javascript of me.</p>
  
  <p>The opntions that i have evaluated it's save the data in a hidden div or save with localstorage/cookies.</p>
  
  <p>Thanks for the help!</p>
  
  <p><strong>EDIT 20/11:</strong></p>
  
  <pre><code>    function load_location() {
          navigator.geolocation.getCurrentPosition(save_location, handleLocationError, {maximumAge: 0, timeout: 1000, enableHighAccuracy: true});
      }
  
      function handleLocationError(error) {
          alert(error.code + ' - ' + error.message);
      }
  
      function save_location(position) {
          localStorage.clear();
          ls_save('latitude',position.coords.latitude);
          ls_save('longitude',position.coords.longitude);
          ls_save('accuracy',position.coords.accuracy);
          ls_save('altitude',position.coords.altitude);
          ls_save('altitudeAccuracy',position.coords.altitudeAccuracy);
          ls_save('heading',position.coords.heading);
          ls_save('speed',position.coords.speed);
  
      }
  
      function ls_save(key,value) {
          localStorage.setItem(key, value); 
      }
  
      function get_location() {
      while(typeof localStorage['latitude'] === 'string') {
          return localStorage.getItem("latitude");
      }
  }
  
      load_location();
  //Code
      console.log(get_location());
  </code></pre>
  
  <p>The new code after the comments. I do not know how performance this solution...
  I have replaced console.log with alert and i get undefined then in some cases is not asynchronous.</p>
  
  <p><strong>Edit: 22/11:</strong>
  Fixed the while</p>