Search code examples
javajakarta-eeblackberry

please tell me when to use getInstance() method in java.


When to use the getInstance() method in java and what is the meaning of getInstance(null)?

locationProvider = LocationProvider.getInstance(null); 

can anyone tell me the meaning of the above line?


Solution

  • The following code will give you the latitude and longitude. getInstance() will give back the instance of that particular class.

        Criteria myCriteria = new Criteria();
        myCriteria.setCostAllowed(false);
        LocationProvider myLocationProvider = LocationProvider.getInstance(myCriteria);
        Location myLocation = myLocationProvider.getLocation(300);
        latitude  = myLocation.getQualifiedCoordinates().getLatitude();
        longitude = myLocation.getQualifiedCoordinates().getLongitude();