Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Below is the code, I have the doubt: 

locationProvider = LocationProvider.getInstance(null); 

Can anyone tell me when one should use the getInstance() method and what getInstance(null) means? 

1 Answer

0 votes
by (19.7k points)

This code provides the latitude and longitude and getInstance() will give you 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();

Interested in Java? Check out this Java Certification by Intellipaat.   

Browse Categories

...