title: TypeError: this is undefined
body: <p>I am trying to get user's latitude and longitude from the html5 location functions. After that using google maps API i want to get user's current location name. This is a code i wrote in jquery. But i am experiencing an error </p>
  
  <p>"TypeError: this is undefined "</p>
  
  <p>What is going wrong here ? Have I missed something ?</p>
  
  <pre><code> function getLocation()    //getting the users location 
         {
                    alert("inside show getlocation");
                    var locationerror = document.getElementById('locationerror'); 
  
                    if(navigator.geolocation)
                    {
                      navigator.geolocation.getCurrentPosition(showPosition);
                    }
                    else
                    {
                       locationerror.innerHTML = "Please enable current location in your browser to get best results. Click &lt;a href = 'https://www.google.co.in/search?q=enable+current+location+in+browser'&gt;here&lt;a&gt; for help.";
                    }
         };
  
         getLocation();         
  
         function showPosition(position)  //get user's  current location name
             {
                   alert("inside show position");
                   mylat = position.coords.latitude;
                   mylong = position.coords.longitude; 
  
                   var latlng2 = new google.maps.LatLng(mylat,mylong);
  
                   alert(latlng2);
                    geocoder = new google.maps.Geocoder();
                    if (geocoder) 
  
                    {
                       var apilink2 = "http://maps.googleapis.com/maps/api/geocode/json?";
  
                      $.ajax(
                      {
                        type: "GET",
                        url: apilink2,
                        data: {
                           latlng: latlng2,
                           sensor: true           
                              },
                          dataType: "jsonp"
                          }).done(function(response)
                          {
                               alert("done");
                                var currentlocationname = response[0].formatted_address;
  
                                 if( typeof response[0].currentlocationname == 'undefined' )
                                 {
                                     $('#locationerror').innerHTML = "Can't get your current location.";
                                 }
                         });
  
  
  
               alert(currentlocationname);
  </code></pre>