LocationManager getBestProvider - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for LocationManager getBestProvider method.

This code example shows how to use the following methods:getBestProvider, getLastKnownLocation, isProviderEnabled, requestLocationUpdates
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBestProvider, getLastKnownLocation, requestLocationUpdates
    protected void onResume() { 
        super.onResume(); 
        // 現在の状況に最適なプロバイダを取得します。 
        // Criteriaで細かい条件が指定できますが今回はデフォルトで 
        String provider;
        provider = mManager.getBestProvider(new Criteria(), true);
        if (provider == null) {
            // 位置情報が取得できるプロバイダがありません。 
            // Wifiにも3Gにも繋がっていないなど。 
        } 
        mManager.requestLocationUpdates(provider, 0, 0, this);
        // 最後に取得した位置情報を取得 
        Location location = mManager.getLastKnownLocation(provider);
        if (location != null) onLocationChanged(location);
    } 
 
    @Override 
    public void onPause() { 
        super.onPause(); 
        // リスナーを解除 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBestProvider, removeUpdates, requestLocationUpdates
        ifGPSregisterOneShotNetworkUpdate(); 
        locationUpdateManager.removePassiveLocationUpdates();
    } 
 
    private void ifGPSregisterOneShotNetworkUpdate() { 
        String bestEnabledProvider = locationManager.getBestProvider(criteria, true);
        if (bestEnabledProvider != null && LocationManager.GPS_PROVIDER.equals(bestEnabledProvider)) {
            locationManager.removeUpdates(oneShotNetworkLocationListener);
            if (isNetworkProviderEnabled()) { 
                locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, oneShotNetworkLocationListener);
            } 
        } 
    } 
 
    @Override 
    public void stopLocationUpdates() { 
        if (!settings.shouldUpdateLocation()) {
            return; 
        } 
        listeningForActiveLocationUpdates = false;
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBestProvider, getLastKnownLocation, requestLocationUpdates
    // Request updates to the provider 
    private void requestUpdates() { 
	Criteria c = new Criteria();
	c.setCostAllowed(false);
	c.setAccuracy(Criteria.ACCURACY_FINE);
	String provider = mLocMan.getBestProvider(c, true);
	Log.d(LOG_TAG, "requestLocationUpdates with " + this.interval + " milliseconds");
	mLocMan.requestLocationUpdates(provider, this.interval, 0, this);
	if (cLoc == null) {
	    cLoc = mLocMan.getLastKnownLocation(provider);
	} 
// 	List<String> providers = mLocMan.getProviders(c, true); 
// 	for (String provider : providers) { 
// 	} 
    } 
 
 
 
    public Location getLocation()
    { 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBestProvider, requestLocationUpdates
        this.locationManager = locationManager;
    } 
 
    @Override 
    public void startActiveLocationUpdates(LocatorSettings settings, Criteria criteria, PendingIntent pendingIntent) {
        String provider = locationManager.getBestProvider(criteria, true);
        if (provider == null) {
            return; 
        } 
        long minTime = settings.getUpdatesInterval();
        float minDistance = settings.getUpdatesDistance();
        locationManager.requestLocationUpdates(provider, minTime, minDistance, pendingIntent);
    } 
 
    @Override 
    public void startPassiveLocationUpdates(LocatorSettings settings, PendingIntent pendingIntent) {
        long minTime = settings.getPassiveUpdatesInterval();
        float minDistance = settings.getPassiveUpdatesDistance();
        locationManager.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, minTime, minDistance, pendingIntent);
    } 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBestProvider, getLastKnownLocation
			 
			// Listen to the user location 
			LocationManager locationManager = (LocationManager)(arg0.getActivity().getSystemService(Context.LOCATION_SERVICE));
			Criteria locationCriteria = new Criteria();
			locationCriteria.setAccuracy(Criteria.ACCURACY_COARSE);
			String locationProvider = locationManager.getBestProvider(locationCriteria, true);
			Location location = locationManager.getLastKnownLocation(locationProvider);
			if (location != null)
			{ 
				float latitude = (float)location.getLatitude();
				float longitude = (float)location.getLongitude();
				FlurryAgent.setLocation(latitude, longitude);
				 
				Log.d(TAG, "Retrieved user location: ("+latitude+", "+longitude+")");
			} 
			else 
			{ 
				Log.d(TAG, "Couldn't retrieve user location (locationProvider = " + locationProvider + ")");
			} 
		} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBestProvider
	private void initLocationManager(Context context) {
		// Acquire a reference to the system Location Manager 
		mLocationManager = (LocationManager) context
				.getSystemService(Context.LOCATION_SERVICE);
 
		mLocationProvider = mLocationManager.getBestProvider(new Criteria(),
				false); 
	} 
 
	public void startService() { 
		if (!running) {
			Log.v(TAG, "START LOCATION SERVICE, PROVIDER:" + mLocationProvider);
			running = true;
			mLocationManager.requestLocationUpdates(mLocationProvider, 0, 0,
					mLocationListener);
		} 
	} 
 
	public void stopService() { 
		if (running) {
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBestProvider, getLastKnownLocation
-66
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBestProvider, getLastKnownLocation, isProviderEnabled
			Start Google Maps on the emulator and request the current geo-position, this will allow you to activate the GPS. Send new GPS coordinates to the Android emulator. 
			 
			ESTO ES---> IR A LOS MAPAS Y JUGUETEAR, ENTONCES SE ACTIVA EL GPS 
			LUEGO ENVIAMOS COORDENADAS DESDE CONSOLA O DEVICE CONTROLLER 
			*/ 
			if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
				Log.i(TAG, "GPS Activado");
			}  
			if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
				Log.i(TAG, "Network Activado");
			}  
			if (locationManager.isProviderEnabled(LocationManager.PASSIVE_PROVIDER)){
				Log.i(TAG, "Passive Activado");
			} 
			 
			//OBTENEMOS PROVIDER 
			Criteria criteria = new Criteria();//podemos usar el obj criteria por defecto, no hace falta setearle nada si no queremos nada concreto
			criteria.setAccuracy(Criteria.ACCURACY_FINE);
			String locProvider = locationManager.getBestProvider(criteria, false);
			Location location = locationManager.getLastKnownLocation(locProvider);

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getBestProvider
        assertEquals("GNSS", locationManager.getBestProvider(new Criteria(), false));
    } 
 
    @Test 
    public void shouldReturnNullWhenBestProviderIsNotSet() throws Exception { 
        assertNull(locationManager.getBestProvider(new Criteria(), true));
    } 
 
    private Listener addGpsListenerToLocationManager() {
        Listener listener = new TestGpsListener();
        locationManager.addGpsStatusListener(listener);
        return listener;
    } 
 
    private static class TestLocationListener implements LocationListener {
        @Override 
        public void onLocationChanged(Location location) {
        } 
 
        @Override 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related LocationManager getBestProvider Questions & Answers:

Other LocationManager getBestProvider Examples

29:	    // default
30:	    Criteria criteria = new Criteria();
31:	    provider = locationManager.getBestProvider(criteria, false);
32:	    Location location = locationManager.getLastKnownLocation(provider);
33:

Read More

getBestProvider Method Overview
Returns the name of the provider that best meets the given criteria.
See Code Examples for other Android LocationManager Methods: