Example #1
0
  private void comenzarLocalizacion() {
    // Obtenemos una referencia al LocationManager
    locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    // Obtenemos la última posición conocida
    Location loc = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

    // Mostramos la última posición conocida
    mostrarPosicion(loc);

    // Nos registramos para recibir actualizaciones de la posición
    locListener =
        new LocationListener() {
          @Override
          public void onLocationChanged(Location location) {
            mostrarPosicion(location);
          }

          @Override
          public void onProviderDisabled(String provider) {
            // Toast.makeText(MainActivity.this,"Provider OFF",Toast.LENGTH_SHORT).show();
            GPSActivo = false;
          }

          @Override
          public void onProviderEnabled(String provider) {
            // Toast.makeText(MainActivity.this,"Provider ON ",Toast.LENGTH_SHORT).show();
          }

          @Override
          public void onStatusChanged(String provider, int status, Bundle extras) {
            Log.i("", "Provider Status: " + status);
            Toast.makeText(
                    MainActivity.this,
                    "Provider Status: " + String.valueOf(status),
                    Toast.LENGTH_SHORT)
                .show();
          }
        };

    if (locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {

      locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 15000, 0, locListener);
      GPSActivo = true;
    } else {
      locListener.onProviderEnabled(LocationManager.GPS_PROVIDER);
    }
  }
 public void onProviderEnabled(String provider) {
   if (locationListener != null) locationListener.onProviderEnabled(provider);
 }
Example #3
0
 @Override
 public void onProviderEnabled(String provider) {
   mLocationListener.onProviderEnabled(provider);
 }