title: Get the previous found geolocation address
body: <p>I've got a script that gets user location. Problem is it takes some time to load, sometimes the string doesn't show up in the page.
  Since I'm new to javascript I don't know what to do from here.
  I'm now trying to add some function that sets a timeout and if I can't load the geolocation it shows the last geolocation that was shown before (possibly saved in browser or something)</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;head&gt;
      &lt;script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"&gt;&lt;/script&gt;
      &lt;script type="text/javascript"&gt;
          function initialize() {
              geocoder = new google.maps.Geocoder();
          }
          var geocoder;
          if (navigator.geolocation) {
              navigator.geolocation.getCurrentPosition(function (position) {
                  var lat = position.coords.latitude;
                  var lng = position.coords.longitude;
                  geocodeLatLng(lat, lng);
              }, function (error) {
                  alert("Erro interno.");
              });
          }
          function geocodeLatLng(lat, lng) {
              var latlng = new google.maps.LatLng(lat, lng);
              geocoder.geocode({ 'latLng': latlng }, function (results, status) {
                  if (status == google.maps.GeocoderStatus.OK) {
                      console.log(results)
                      if (results[1]) {
                          //var add = results[0].formatted_address;
                          //document.getElementById("address").innerHTML = add;
                          for (var i = 0; i &lt; results[0].address_components.length; i++) {
                              var addr = results[0].address_components[i];
                              if (addr.types[0] == ['locality']) {    // City
                                  document.getElementById("locality").innerHTML = addr.long_name;
                              }
                          }
                      } else
                          alert("Sem resultados.");
                  } else
                      alert("Geocoder falhou devido ao seguinto erro: " + status);               
              });
          }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body onload="initialize()"&gt;
      &lt;h4 id="locality"&gt;&lt;/h4&gt;
  &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>