M0286_Libro Curso

3: Próximas generaciones

if (mLocationManager.isProviderEnabled(LocationMa

nager. GPS_PROVIDER )) {

// ejecutamos el bucle de mensajes Looper.prepare();

mLocationListener = new MyLocationListener(); // definimos el tiempo de refresco minimo y la mLocationManager.requestLocationUpdates( LocationManager. GPS_PROVIDER , 0,

distancia minima

0, mLocationListener);

Looper.loop(); Looper.myLooper().quit();

} else {

// cuadro de texto emergente si no encuentra

señal de GPS

Toast.makeText(getBaseContext(),

getResources().getString(R. Toast. LENGTH_LONG ).show();

string. gps_signal_not_found ),

}

} private Handler handler = new Handler() { @Override

public void handleMessage(Message msg) { pd.dismiss();

mLocationManager.removeUpdates(mLocationListener); if (currentLocation != null) { outlat.setText(“Latitud: “ + outlong.setText(“Longitud: “ +

currentLocation.getLatitude()); currentLocation.getLongitude()); } } };

private class MyLocationListener implements public void onLocationChanged(Location location) { if (location != null) { Toast.makeText(getBaseContext(), getResources().getString(R.

LocationListener {

string. gps_signal_found ),

Toast. LENGTH_LONG ).show();

setCurrentLocation(location); handler.sendEmptyMessage(0);

181

Made with FlippingBook - Online catalogs