get location provider to use - Android Map

Android examples for Map:Location Provider

Description

get location provider to use

Demo Code


import android.content.Context;
import android.location.Address;
import android.location.Criteria;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationManager;
import java.io.IOException;
import java.util.List;

public class Main{
    /**// w w  w . j ava2s  . c  om
     * get location provider to use
     * @param locationManager
     * @return String provider
     */
    public static String detectLocationProvider(
            LocationManager locationManager) {
        Common.log("LocationUtils detectLocationProvider");
        String provider;
        Criteria criteria = new Criteria();
        criteria.setPowerRequirement(Criteria.POWER_LOW);
        criteria.setAccuracy(Criteria.ACCURACY_COARSE);
        Boolean getEnabledProvider = true;
        //with criteria ACCURACY_COARSE, provider 'network' is selected
        //with default criteria or ACCURACY_FINE, provider 'gps' is selected
        provider = locationManager.getBestProvider(criteria,
                getEnabledProvider);
        return provider;
    }
}

Related Tutorials