title: How to use asynchronous Javascript?
body: <p>I am using Google maps to get address in mobile application. Code is working fine when there is an internet connection. If not then my app takes 1 minute to load or sometimes it shows an application error. This is due to loading a URL within the script, so I wanted to load my script asynchronously. Can anyone give me some logic to solve my issue, how do I rewrite the below script asynchronously?</p>
  
  <pre><code>&lt;script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true"&gt;
  function address()
  {
                var geocoder ;
                geocoder = new google.maps.Geocoder();
                var latlng = new google.maps.LatLng(latitude, longitude);
                geocoder.geocode({'latLng': latlng}, function(results, status) 
                  {                   
                  if (status == google.maps.GeocoderStatus.OK)
                   {
                          if (results[0])
                          {
                             var add= results[0].formatted_address ;
                             document.getElementById("location").innerHTML="Location : " + add ;
                          }
                          else 
                          {
                             document.getElementById("location").innerHTML="No Results found " ;
                          }
                  }
                   else
                  {
                  //document.getElementById("location").innerHTML="Geocoder failed due to: " + status;
                  //alert("Geocoder failed due to: " + status);               
                  }
                  });
  }
  </code></pre>
  
  <p></p>