title: Current latitude and longitude in a BlackBerry app
body: <p>I want to get the user's latitude and longitude in my BlackBerry app, and then generate the maps according to it.</p>
  
  <p>How can I do that?</p>
  
  <p>my code is:</p>
  
  <pre><code>import java.util.Timer;
  import java.util.TimerTask;
  
  import javax.microedition.location.Criteria;
  import javax.microedition.location.Location;
  import javax.microedition.location.LocationListener;
  import javax.microedition.location.LocationProvider;
  import javax.microedition.location.QualifiedCoordinates;
  
  import net.rim.device.api.system.Application;
  
  
  
  
  public class GPS_Location 
  {
      private String log;
        double longi;
        double lati;
  
      public GPS_Location()
      {
          new LocationTracker();
      }
      public boolean onClose()
      {
          Application.getApplication().requestBackground();       
          return false;
      }
  
  
  class LocationTracker extends TimerTask
  {
      private  double longitude, latitude;
  
      private Timer timer;
      private LocationProvider provider;
      Criteria cr;
  
      public LocationTracker() 
      {
          timer = new Timer();
          cr= new Criteria();
          resetGPS();
  
          timer.schedule(this, 0, 60000);
      }
  
      public void resetGPS()
      {
  
          try 
          {
              provider = LocationProvider.getInstance(cr);
              if(provider != null) 
              {
                  /*provider.setLocationListener(null, 0, 0, 0);
                  provider.reset();
                  provider = null;*/
                  provider.setLocationListener(new MyLocationListener(), 3, -1, -1);
              }
  
              //provider = LocationProvider.getInstance(null);
  
          } catch(Exception e)
          { 
  
          }
      }
  
  
      public void run() 
      {
          System.out.println("********************");
      }
  
      private class MyLocationListener implements LocationListener 
      {
          public void locationUpdated(LocationProvider provider, Location location)
          {
              if(location != null &amp;&amp; location.isValid())
              {               
                  QualifiedCoordinates qc = location.getQualifiedCoordinates();
  
                  try 
                  {
                      lati = location.getQualifiedCoordinates().getLatitude();
                      System.out.println("********************latitude :: "+lati);
                      longi = location.getQualifiedCoordinates().getLongitude();
                      System.out.println("********************longitude ::"+longi);
  
                  } 
                  catch(Exception e)
                     { 
  
                     }
              }
  
          }
  
          public void providerStateChanged(LocationProvider provider, int newState)
          {
              //LocationTracker.this.resetGPS();
               if(newState == LocationProvider.TEMPORARILY_UNAVAILABLE)
                  {
                      provider.reset();
                      provider.setLocationListener(null, 0, 0, -1);
                  }
          }
      }
    } 
  }
  </code></pre>