Change the criteria for obtaining location information

  1. Import the following classes:
    • javax.microedition.location.Criteria
    • javax.microedition.location.LocationProvider
  2. Import the LocationListener interface.
  3. Implement the LocationListener interface.
  4. Create an instance of the Criteria class.
    Criteria criteria = new Criteria();
  5. Invoke the setHorizontalAccuracy(), setVerticalAccuracy(), setCostAllowed(), and setPreferredPowerConsumption() methods of the new Criteria object to specify the new criteria.
  6. Invoke LocationProvider.reset() using the LocationProvider object with the criteria that you want to change.
    provider.reset();
  7. Specify the LocationListener to null to unregister any LocationListeners that are currently associated with the LocationProvider object.
    provider.setLocationListener(null, -1, -1, -1);
  8. Invoke LocationProvider.getInstance() using the new Criteria object as a parameter to create a new instance of a LocationProvider object. Assign the value that the method returns to the LocationProvider with the criteria that you want to change.
    provider = LocationProvider.getInstance(criteria);
  9. Invoke LocationProvider.setLocationListener() to associate a new LocationListener with the LocationProvider object.
    provider.setLocationListener(locListener, -1, -1, -1);

Was this information helpful? Send us your comments.