title: How to make latitude and longitude global variables?
body: <p>I have made latitude and longtitude global variables.</p>
  
  <p>It works fine in the <code>MyLocationListener</code> class as it displays the current location latitude and longitude but when it loads url ( <code>http://maps.google.com/maps?" + "saddr="
                  + currentLattitude + "," + currentLongtitude
                  + "&amp;daddr=27.11,85.11")</code> ) in webview, it loads the value 0 and 0.  </p>
  
  <p>Why?</p>
  
  <pre><code>public class ShowMapActivity extends Activity {
  
  private WebView webView;
  double currentLattitude;
  double currentLongtitude;
  
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.webview);
  
      LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
      LocationListener mlocListener = new MyLocationListener();
      mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
              mlocListener);
  
      webView = (WebView) findViewById(R.id.webView1);
      webView.getSettings().setJavaScriptEnabled(true);
      webView.setWebViewClient(new WebViewClient());
      webView.loadUrl("http://maps.google.com/maps?" + "saddr="
              + currentLattitude + "," + currentLongtitude
              + "&amp;daddr=27.11,85.11");
  
  }
  
  public class MyLocationListener implements LocationListener
  {
      @Override
      public void onLocationChanged(Location loc)
      {
          currentLattitude = loc.getLatitude();
  
          currentLongtitude = loc.getLongitude();
  
          Toast.makeText(
                  getApplicationContext(),
  
                  "Latitude is: " + currentLattitude + " Longitude is: "
                          + currentLongtitude,
  
                  Toast.LENGTH_SHORT).show();
      }
  
      @Override
      public void onProviderDisabled(String provider)
      {
  
          Toast.makeText(getApplicationContext(),
  
          "Gps Disabled",
  
          Toast.LENGTH_SHORT).show();
  
      }
  
      @Override
      public void onProviderEnabled(String provider)
      {
  
          Toast.makeText(getApplicationContext(), "Gps Enabled",
  
          Toast.LENGTH_SHORT).show();
  
      }
  
      @Override
      public void onStatusChanged(String provider, int status, Bundle extras)
      {
  
      }
  }
  }
  </code></pre>