0

I am using Location Service in my app as follows:

LocationManager locM = (LocationManager) getSystemService(LOCATION_SERVICE);                
            Criteria criteria = new Criteria();
            criteria.setAccuracy(Criteria.ACCURACY_COARSE);
            criteria.setAltitudeRequired(false);
            criteria.setBearingRequired(false);
            criteria.setCostAllowed(true);
            criteria.setPowerRequirement(Criteria.POWER_HIGH);
            criteria.setSpeedRequired(false);


            String currentProvider = locM.getBestProvider(criteria, true);
            Log.d("Location", "currentProvider: " + currentProvider);


            Location currentLocation = locM.getLastKnownLocation(currentProvider);

            if(currentLocation == null){
                locM.requestLocationUpdates(currentProvider, 0, 0, locationListener);
            }

And I add permissions of network and locations in Manifest.xml. When I test this code in my Android phone earlier today, this line String currentProvider = locM.getBestProvider(criteria, true); always returned null. After some googling, I find out that this is caused by the settings of my phone. I should turn settings->location->use wireless networks on.

I am curious that why other app(e.g. google maps) can work well even when I turn this off. Because I never modify the settings of location before, and all other apps using location service in my phone works well. Is there some way to modify settings in code?

4

1 回答 1

0

只要发现有很多第三方库比内置的位置类工作得更好。就像中国的百度一样。请参考这个页面:百度Location sdk的Wiki

于 2013-04-12T05:43:12.943 回答