Retrieve a location provider by using the BlackBerryLocationProvider class

  1. Import the required classes.
    import net.rim.device.api.gps.*;
    import javax.microedition.location.*;
  2. Create a class and a constructor.
    public class handleGPS
    {
        static BlackBerryCriteria myCriteria;
    
        public handleGPS()
        {
        }
    }
  3. In the constructor, create a try/catch block. In the block, create an instance of the BlackBerryCriteria class and pass the GPS mode to the constructor. Create a second try/catch block, then create an instance of the BlackBerryLocationProvider class by invoking getInstance() to retrieve an instance of the BlackBerryCriteria object.
            try
            {
                myCriteria = new BlackBerryCriteria(GPSInfo.GPS_MODE_ASSIST);
    
                try
                {
                    BlackBerryLocationProvider myProvider =
                      (BlackBerryLocationProvider)
                        LocationProvider.getInstance(myCriteria);
                }
                catch ( LocationException lex )
                {
                    return;
                }
            }
            catch ( UnsupportedOperationException ex )
            {
                return;
            }
        }
    }

Was this information helpful? Send us your comments.